NexusFi: Find Your Edge


Home Menu

 





Another Trail Stop question


Discussion in EasyLanguage Programming

Updated
    1. trending_up 3,201 views
    2. thumb_up 0 thanks given
    3. group 2 followers
    1. forum 11 posts
    2. attach_file 0 attachments




 
 

Another Trail Stop question

 
gurji
Miami, Florida
 
Posts: 35 since Apr 2022
Thanks Given: 1
Thanks Received: 10

I will try to make this as simple as I can.

I place a long order at $90.

My stop loss is $80.

My Target is $100.


Now I want to add a trail stop. So instead of the $100 target, I want the following:
When price reaches $100, then create a $5 trail stop.

So if it reaches $100, the worst I will get is $95. If it continues up to $115 and goes back down to $110, then it will exit at $110.

If it reaches $105 and goes back to $100, it will exit at $100.


How can I set this in easylanguage?


Can you help answer these questions
from other members on NexusFi?
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
Exit Strategy
NinjaTrader
Deepmoney LLM
Elite Quantitative GenAI/LLM
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
61 thanks
Funded Trader platforms
38 thanks
NexusFi site changelog and issues/problem reporting
27 thanks
GFIs1 1 DAX trade per day journal
18 thanks
The Program
18 thanks
 
 
syswizard's Avatar
 syswizard 
Philadelphia PA
 
Experience: Advanced
Platform: Multicharts
Broker: Ironbeam, Rithmic
Trading: Emini ES / NQ / CL / RTY / YM / BTC
Posts: 344 since Jan 2019
Thanks Given: 20
Thanks Received: 146

if MarketPosition <> 0 and OpenPositionProfit >= 100 Then
Begin
SetStopPosition;
SetDollarTrailing(100);
End;

 
gurji
Miami, Florida
 
Posts: 35 since Apr 2022
Thanks Given: 1
Thanks Received: 10



syswizard View Post
if MarketPosition <> 0 and OpenPositionProfit >= 100 Then
Begin
SetStopPosition;
SetDollarTrailing(100);
End;


Thanks, but something still not right. This is what I have. tgamt is trigger amount in ticks for when to start the trail stop.
slamt is the stop loss amount in ticks.

 
Code
SetStopLoss(slamt);

if MarketPosition <> 0 and Openpositionprofit >= tgamt Then
	Begin
		SetStopPosition;
		SetDollarTrailing(50); //50 is $50 which is 5 ticks.
	End

 
 
syswizard's Avatar
 syswizard 
Philadelphia PA
 
Experience: Advanced
Platform: Multicharts
Broker: Ironbeam, Rithmic
Trading: Emini ES / NQ / CL / RTY / YM / BTC
Posts: 344 since Jan 2019
Thanks Given: 20
Thanks Received: 146


gurji View Post
Thanks, but something still not right. This is what I have. tgamt is trigger amount in ticks for when to start the trail stop.
slamt is the stop loss amount in ticks.

Both tgamt and slamt must be specified in DOLLARS, not BigPoints, not Ticks.
If you need to, convert your input in ticks to dollars:
So use this: tgamt_ticks * dollarspertick, slamt_ticks * dollarspertick

 
gurji
Miami, Florida
 
Posts: 35 since Apr 2022
Thanks Given: 1
Thanks Received: 10


syswizard View Post
Both tgamt and slamt must be specified in DOLLARS, not BigPoints, not Ticks.
If you need to, convert your input in ticks to dollars:
So use this: tgamt_ticks * dollarspertick, slamt_ticks * dollarspertick


Ok, my mistake. tgamt and slamt are dollar amounts. Not ticks.
Regardless, that didn't solve it. I even changed the IF statement to check is Openpositionprofit is greater than 0, and it still returns false.

 
Code
value7 = Text_New(Date, Time, High, NumToStr(Openpositionprofit,0));
if MarketPosition <> 0 and Openpositionprofit >= 0  Then
	SetProfitTarget(trailExit) Else
	SetProfitTarget(tgamt);
value7 just prints the value of Openpositionprofit on the chart just so that I can confirm it has a value, which it does. But for some reason, it returns false when tested to see if it is greater than 0.

 
 
syswizard's Avatar
 syswizard 
Philadelphia PA
 
Experience: Advanced
Platform: Multicharts
Broker: Ironbeam, Rithmic
Trading: Emini ES / NQ / CL / RTY / YM / BTC
Posts: 344 since Jan 2019
Thanks Given: 20
Thanks Received: 146


gurji View Post
Ok, my mistake. tgamt and slamt are dollar amounts. Not ticks.
Regardless, that didn't solve it. I even changed the IF statement to check is Openpositionprofit is greater than 0, and it still returns false.

 
Code
value7 = Text_New(Date, Time, High, NumToStr(Openpositionprofit,0));
if MarketPosition <> 0 and Openpositionprofit >= 0  Then
	SetProfitTarget(trailExit) Else
	SetProfitTarget(tgamt);
value7 just prints the value of Openpositionprofit on the chart just so that I can confirm it has a value, which it does. But for some reason, it returns false when tested to see if it is greater than 0.

Something is wrong with your signal's set-up and properties.
Try using PositionProfit(0) in place of OpenPositionProfit.
This code is within a SIGNAL, correct ?
Note: it won't work in an INDICATOR.

 
gurji
Miami, Florida
 
Posts: 35 since Apr 2022
Thanks Given: 1
Thanks Received: 10


syswizard View Post
Something is wrong with your signal's set-up and properties.
Try using PositionProfit(0) in place of OpenPositionProfit.
This code is within a SIGNAL, correct ?
Note: it won't work in an INDICATOR.

It is in a strategy.
I'll try that and post back here.

 
gurji
Miami, Florida
 
Posts: 35 since Apr 2022
Thanks Given: 1
Thanks Received: 10


syswizard View Post
Something is wrong with your signal's set-up and properties.
Try using PositionProfit(0) in place of OpenPositionProfit.
This code is within a SIGNAL, correct ?
Note: it won't work in an INDICATOR.

Ok, I see what the problem is, I just don't know how to fix it.
PositionProfit or openPositionProfit both show the profit at the close of the previous candle. But show 0 for the current candle. So 0 is never >= to tgamt, and therefore it doesn't trigger the trail stop.

 
gurji
Miami, Florida
 
Posts: 35 since Apr 2022
Thanks Given: 1
Thanks Received: 10


syswizard View Post
Something is wrong with your signal's set-up and properties.
Try using PositionProfit(0) in place of OpenPositionProfit.
This code is within a SIGNAL, correct ?
Note: it won't work in an INDICATOR.

Ok, it is absolutely what I said. The trigger to start the the trail stop order isn't working, because it is looking at the close price of the previous bar and not the current price of the current candle.

 
 
syswizard's Avatar
 syswizard 
Philadelphia PA
 
Experience: Advanced
Platform: Multicharts
Broker: Ironbeam, Rithmic
Trading: Emini ES / NQ / CL / RTY / YM / BTC
Posts: 344 since Jan 2019
Thanks Given: 20
Thanks Received: 146



gurji View Post
Ok, it is absolutely what I said. The trigger to start the the trail stop order isn't working, because it is looking at the close price of the previous bar and not the current price of the current candle.

That is not the correct behavior as the Set statements should be active in the current bar. They are designed to operate INTRABAR and don't require [IntraBarOrderGeneration] to be on. It is independent of that condition.
The only thing I can think of is that the Set statement is not being called after the close of the last bar. It must be called in order to be active.

Please contact MC tech support with this problem and be ready to demonstrate this problem.


 



Last Updated on September 21, 2022


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts