Trendline target exit

Questions about MultiCharts and user contributed studies.
designer01
Posts: 80
Joined: 02 Feb 2010

Trendline target exit

Postby designer01 » 27 Jun 2013

I have a Manual Trendline Profit Target exit signal PL code (code below) that it's supposed to exit an input "x" number of shares when hit but for some reason it always exits the original entry shares. Any suggestions how the PLCode it may be fixed? Thanks in advance.

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);

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: Trendline target exit

Postby Andrew MultiCharts » 28 Jun 2013

The keyword "total" should be used.

designer01
Posts: 80
Joined: 02 Feb 2010

Re: Trendline target exit

Postby designer01 » 28 Jun 2013

Thank you Andrew but where would I use the keyword "total"?
Thanks

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: Trendline target exit

Postby Andrew MultiCharts » 28 Jun 2013

Examples:

Code: Select all

...
Sell ( "TLProfitLX" ) 3 contracts total next bar at Market;
...
Buy To Cover ( "TLProfitSX" ) 3 contracts total next bar at Market;
...


Return to “MultiCharts”