03242022 $176 Profit TradeStation Automated Trading

Bullish today, TQQQ opened at $54.43 closed at $57.02; SOXL opened at $37.82 closed at 42.09! Racked in $176 profit, please find below the trades for the day (only the last few are shown):

03242022 $176 Profit TradeStation Automated Trading

Traded TQQQ and SOXL with 3 sec bars/candles applying MACD Histogram logic. There was a position with 88 stocks in TQQQ from yesterday and it was closed in pre market.

For SOXL we split the existing logic being used in TQQQ. The major shift is using IntrabarOrderGeneration as true in Sell logic. Another major difference is that to maximize profit we ride with uptrend till it dies down. So we skip until Close < Open and sell instantly. Please find the source code of logic:

//BUY logic
[IntrabarOrderGeneration = false]

inputs:  
	BuySetProfitTargetTrue( 0 ) [DisplayName = "BuySetProfitTargetTrue", ToolTip = 
	 "Enter SetPercentTrailing when buying setting."],
	AvgentrypriceTrue( 1 ) [DisplayName = "AvgentrypriceTrue", ToolTip = 
	 "Enter Avgentryprice = 1 else Close."],
	SharesToBuy( 1 ) [DisplayName = "SharesToBuy", ToolTip = 
	 "Enter SharesToBuy for a single trade."],
	BuyTimeCondition( Time > 0929 and Time <= 1549 ) [DisplayName = "BuyTimeCondition", ToolTip = 
	 "Enter buying time condition if day trading."],
	SellTimeCondition( Time > 0929 and Time <= 1600 ) [DisplayName = "SellTimeCondition", ToolTip = 
	 "Enter selling time condition if day trading."],
	FastLength( 12 ) [DisplayName = "FastLength", ToolTip = 
	 "Enter number of bars to use in calculation of shorter length moving average."], 
	SlowLength( 26 ) [DisplayName = "SlowLength", ToolTip = 
	 "Enter number of bars to use in calculation of longer length moving average."], 
	MACDLength( 9 ) [DisplayName = "MACDLength", ToolTip = 
	 "Moving Average Convergence Divergence Length.  Enter the number of bars to use in smoothing the MACD value."];
	
variables:  
	MyMACD( 0 ), 
	MACDAvg( 0 ),
	MACDDiff( 0 );

MyMACD = MACD( Close, FastLength, SlowLength );
MACDAvg = XAverage( MyMACD, MACDLength );
MACDDiff = MyMACD - MACDAvg;
//RSIValue = RSI( Close, 14 );

{ CB > 2 check used to avoid spurious cross confirmation at CB = 2 (at CB = 1, MyMACD and MACDAvg will be the same) }
if CurrentBar > 2
and MACDDiff < 0 and MACDDiff[1] < MACDDiff and MACDDiff[1] < MACDDiff[2] then Begin	

	if Marketposition = 0 and BuyTimeCondition Then 
		//Buy ( !( "H" ) ) SharesToBuy shares next bar at Close Limit
		Buy ( !( "H" ) ) SharesToBuy shares next bar at Market
	Else Begin
		//NumPositions = GetNumPositions(GetAccountID);
		//By using SellTimeCondition we are making sure that the sell gets triggered till EOD regular trading hours
		//Buy only when Close is lower then last Entryprice
		If SellTimeCondition {and Close < Entryprice} Then Begin
			//For every 50 stocks increment the ratio of buying by 1 eg from 51 to 100 postiions buy 3 times
			If Currentcontracts < 51 Then
				Buy ( !( "Hn1" ) ) (SharesToBuy * 2) shares next bar at Close Limit;

			If Currentcontracts > 50 and Currentcontracts < 101 Then
				Buy ( !( "Hn2" ) ) (SharesToBuy * 3) shares next bar at Close Limit;

			If Currentcontracts > 100 and Currentcontracts < 151 Then
				Buy ( !( "Hn3" ) ) (SharesToBuy * 4) shares next bar at Close Limit;

			If Currentcontracts > 150 and Currentcontracts < 201 Then
				Buy ( !( "Hn4" ) ) (SharesToBuy * 5) shares next bar at Close Limit;

			If Currentcontracts > 200 and Currentcontracts < 251 Then
				Buy ( !( "Hn5" ) ) (SharesToBuy * 6) shares next bar at Close Limit;

			If Currentcontracts > 250 and Currentcontracts < 301 Then
				Buy ( !( "Hn6" ) ) (SharesToBuy * 7) shares next bar at Close Limit;

			If Currentcontracts > 300 and Currentcontracts < 351 Then
				Buy ( !( "Hn7" ) ) (SharesToBuy * 8) shares next bar at Close Limit;

			If Currentcontracts > 350 and Currentcontracts < 401 Then
				Buy ( !( "Hn8" ) ) (SharesToBuy * 9) shares next bar at Close Limit;

			If Currentcontracts > 400 and Currentcontracts < 451 Then
				Buy ( !( "Hn9" ) ) (SharesToBuy * 10) shares next bar at Close Limit;

			If Currentcontracts > 450 and Currentcontracts < 501 Then
				Buy ( !( "Hn10" ) ) (SharesToBuy * 11) shares next bar at Close Limit;

			If Currentcontracts > 500 and Currentcontracts < 551 Then
				Buy ( !( "Hn11" ) ) (SharesToBuy * 12) shares next bar at Close Limit;
		End;
	End;
	Print("BUY Symbol: ", Symbol, " Time: ", Time, " NetProfit: ", NetProfit, " GrossProfit: ", GrossProfit, " GrossLoss: ", GrossLoss, " OpenPositionProfit: ", OpenPositionProfit, " Avgentryprice: ", Avgentryprice, " Currentcontracts: ", Currentcontracts);
	
End;
//SELL logic
[IntrabarOrderGeneration = true]

inputs:
	SellSetProfitTargetTrue( 0 ) [DisplayName = "SetSetProfitTargetTrue", ToolTip = 
	 "Enter SetPercentTrailing for selling setting."],
	AvgentrypriceTrue( 1 ) [DisplayName = "AvgentrypriceTrue", ToolTip = 
	 "Enter Avgentryprice = 1 else Close."],
	ProfitPercent( 0.002 ) [DisplayName = "ProfitPercent", ToolTip = 
	 "Enter Profit Percent."],
	ProfitCents ( 0 ) [DisplayName = "ProfitCents", ToolTip = 
	 "Enter Profit per share."],
	SellTimeCondition( Time > 0929 and Time <= 1600 ) [DisplayName = "SellTimeCondition", ToolTip = 
	 "Enter selling time condition if day trading."];

variables:  
	Dummy( 0 );

if Marketposition > 0 and Avgentryprice < Close and SellTimeCondition {and Currentcontracts > 1} then Begin
	Print("SELL Symbol: ", Symbol, " Time: ", Time, " NetProfit: ", NetProfit, " GrossProfit: ", GrossProfit, " GrossLoss: ", GrossLoss, " OpenPositionProfit: ", OpenPositionProfit, " Avgentryprice: ", Avgentryprice, " Currentcontracts: ", Currentcontracts);
	if SellSetProfitTargetTrue = 1 Then Begin
		if ProfitCents > 0 Then Begin
			SetStopShare;
			Setprofittarget(ProfitCents);
		end
		Else Begin
			SetStopShare;
			Setprofittarget(Avgentryprice * ProfitPercent);
		End;
	End
	Else Begin
		If C >= O Then
			Dummy = C
		Else Begin
			if AvgentrypriceTrue <> 1 Then
				Sell all shares next bar at (Close + (Close * ProfitPercent)) Limit
				//Sell all shares next bar at Market
			Else Begin
				if ProfitCents > 0 Then
					Sell all shares next bar at (Avgentryprice + ProfitCents) Limit
				Else
					Sell all shares next bar at (Avgentryprice + (Avgentryprice * ProfitPercent)) Limit;
			End;
		End;
	End;
End;

Leave a Comment