Code: Select all
input:
TLColor( GREEN ),
AllMarketOrders ( FALSE ), {TRUE = Creates Conditional Market orders when the Profit Target is true on the bar close }
CreateTestEntry ( FALSE ), {TRUE = Creates a test position to exit for a real world discretionary position}
SharesLongShort ( 500 ); {Positive shares(500) = Buy Entry, Negative shares(-500) = Sell Short Entry}
variables:
CurrentTLValue( 0 ),
TextStr("");
CurrentTLValue = -1;
if currentbar = 1 and CreateTestEntry then begin
if SharesLongShort >= 1 then
Buy SharesLongShort Shares next bar at Market;
if SharesLongShort <= -1 then
Sell Short -SharesLongShort Shares next bar at Market;
end;
if LastBarOnChart AND Marketposition <> 0 then begin
if Marketposition = 1 then begin
TextStr = "LX - No Profit Order Generated";
if Value99 = 0 then
Value99 = Text_New( D, T, 0, TextStr);
end;
if MarketPosition = -1 then begin
TextStr = "SX - No Profit Order Generated";
if Value99 = 0 then
Value99 = Text_New( D, T, 0, TextStr);
end;
if Value1 <= 0 then
Value1 = TL_FindColor( 3, TLColor );
if Value1 > -1 then
CurrentTLValue = TL_GetValue( Value1, D, T );
if CurrentTLValue > 0 then begin
if CurrentTLValue <> CurrentTLValue[1] AND Value99 > 0 then begin
Text_SetString(Value99," ");
Text_SetLocation( Value99, D, T, 0 );
end;
if MarketPosition = 1 AND CurrentTLValue >= Close then begin
if AllMarketOrders then begin
if Close >= CurrentTLValue then
Sell ( "TLProfitLX" ) next bar at Market;
TextStr = "LX Sell Profit "+numtoStr(CurrentContracts,0)+" at "+numtoStr(CurrentTLValue,2)+" cMarket -->";
end
else begin
Sell ( "TLProfit LX" ) next bar at CurrentTLValue Limit;
TextStr = "LX Sell Profit "+numtoStr(CurrentContracts,0)+" at "+numtoStr(CurrentTLValue,2)+" Limit -->";
end;
end;
if MarketPosition = -1 AND CurrentTLValue <= Close then begin
if AllMarketOrders then begin
if Close <= CurrentTLValue then
Buy To Cover ( "TLProfitSX" ) next bar at Market;
TextStr = "SX Buy To Cover Profit "+numtoStr(-CurrentContracts,0)+" at "+numtoStr(CurrentTLValue,2)+" cMarket -->";
end
else begin
Buy To Cover ( "TLProfit SX" ) next bar at CurrentTLValue Limit;
TextStr = "Sx Buy To Cover Profit "+numtoStr(-CurrentContracts,0)+" at "+numtoStr(CurrentTLValue,2)+" Limit -->";
end;
end;
Text_SetString(Value99, TextStr);
Text_SetLocation(Value99, D, T, CurrentTLValue );
Text_SetStyle( Value99, 1,1);
Text_SetColor( Value99, TLColor);
end;
END;
if atcommentarybar then
Commentary("Reset Strategy 'TL Profit Target' = OK"+NEWLINE);