NexusFi: Find Your Edge


Home Menu

 





Help with simple exit strategy


Discussion in MultiCharts

Updated
      Top Posters
    1. looks_one Speculationist with 4 posts (0 thanks)
    2. looks_two ABCTG with 2 posts (1 thanks)
    3. looks_3 Sinatra Fan with 2 posts (0 thanks)
    4. looks_4 SMCJB with 1 posts (0 thanks)
    1. trending_up 205 views
    2. thumb_up 1 thanks given
    3. group 4 followers
    1. forum 8 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 Speculationist 
Calgary, Alberta/Canada
 
Experience: Advanced
Platform: Tradestation, Multicharts
Broker: IB, AMP
Trading: Stocks, ES, NQ
Posts: 10 since Sep 2012
Thanks Given: 2
Thanks Received: 0

I'm trying to code a simple exit strategy that I can apply to my discressionary trades.

Let's call the bar prior to my entry the signal bar. I'm entering at the High of the signal bar, and I'd like the strategy to place a stop loss order at the low of the signal bar. The target is a function of the high of the signal bar - low of the signal bar times a multiplier.
My problem is that the High and Low of the signal bar keep being recalculated every bar. It's frustrating to watch the orders on the chart keep changing with every bar that passes. Lol.
How can I store these variables in my code so they persist at the original values?

Any help or direction would be great.

Thanks,

Jeff

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
  #2 (permalink)
 
Sinatra Fan's Avatar
 Sinatra Fan 
Orlando FL
 
Experience: Intermediate
Platform: MultiCharts, Ninja
Trading: Emini ES
Posts: 89 since May 2019
Thanks Given: 8
Thanks Received: 10

Do you have any code to show? Might be easier if we can see what you're doing.

But, if it was me...

I would have two variables declared: EntTrgt(0) and ExtTrgt(0)

At the completion of the SIGNAL bar, I would set the value of both of those variables as follows:

If Barstatus = 2 then begin
EntTrgt = H;
ExtTrgt = L;
end;

Also, you are most likely missing some sort of switch that turns on or off so that this test only happens when the SIGNAL bar actually becomes the SIGNAL bar. For example, lets say, if x, y and z then SetTargets = True;

Therefore, going back to the previous suggestion:

If Barstatus = 2 and SetTargets then begin
EntTrgt = H;
ExtTrgt = L;
SetTargets = False;
end;

Of course, then you will need to write out your entry code, but hopefully this helps some.

Reply With Quote
  #3 (permalink)
 Speculationist 
Calgary, Alberta/Canada
 
Experience: Advanced
Platform: Tradestation, Multicharts
Broker: IB, AMP
Trading: Stocks, ES, NQ
Posts: 10 since Sep 2012
Thanks Given: 2
Thanks Received: 0


Thanks for the insights so far. Here is a simple long only script I whipped up that demonstrates the problem....

[IntrabarOrderGeneration = True];

//Long Only

Inputs:
RewardMultiplier( 2 );

Vars:
EMA( 0 ),
ClickStop( 0 ),
ClickTarget( 0 );

EMA = XAverage( C, 21 );

If O < C and L > EMA Then Begin
Buy 1 Contract Next bar at Market;
End;

If Marketposition > 0 Then Begin
ClickStop = (High[ 1 ] - Low[ 1 ]) * 4 ;
ClickTarget = ClickStop * RewardMultiplier;
setstoploss_pt(ClickStop);
setprofittarget_pt(ClickTarget);
end;

It doesn't seem to matter where I put the "ClickStop" Calculation, it keeps happening every bar. I'd like it to store the low of the "signal bar" and leave the top and target orders where they start.

Started this thread Reply With Quote
  #4 (permalink)
 
Sinatra Fan's Avatar
 Sinatra Fan 
Orlando FL
 
Experience: Intermediate
Platform: MultiCharts, Ninja
Trading: Emini ES
Posts: 89 since May 2019
Thanks Given: 8
Thanks Received: 10


Speculationist View Post
Thanks for the insights so far. Here is a simple long only script I whipped up that demonstrates the problem....

[IntrabarOrderGeneration = True];

//Long Only

Inputs:
RewardMultiplier( 2 );

Vars:
EMA( 0 ),
ClickStop( 0 ),
ClickTarget( 0 );

EMA = XAverage( C, 21 );

If O < C and L > EMA Then Begin
Buy 1 Contract Next bar at Market;
End;

If Marketposition > 0 Then Begin
ClickStop = (High[ 1 ] - Low[ 1 ]) * 4 ;
ClickTarget = ClickStop * RewardMultiplier;
setstoploss_pt(ClickStop);
setprofittarget_pt(ClickTarget);
end;

It doesn't seem to matter where I put the "ClickStop" Calculation, it keeps happening every bar. I'd like it to store the low of the "signal bar" and leave the top and target orders where they start.

So if you are trying to set targets based on the candle that met your criteria (If O < C and L > EMA), then I would do what I suggested earlier and save the values of the Hi and Lo to declared variables that get defined once and stays that way until you need to redefine it at a later time. In this case, you are saying if you are long, then set the stop and targets off the last bar... BUT if that doesn't happen then you do it again the next bar and so on. That's why it's recalculating.

Hope that helps

Reply With Quote
  #5 (permalink)
 Speculationist 
Calgary, Alberta/Canada
 
Experience: Advanced
Platform: Tradestation, Multicharts
Broker: IB, AMP
Trading: Stocks, ES, NQ
Posts: 10 since Sep 2012
Thanks Given: 2
Thanks Received: 0

The Sim mode on my Multicharts has decided to not load data at the moment, however when I print the values of "stoploss" and "target" they seam to be holding the same value as new bars prints.
Am I correct in thinking that this code should be doing the trick?

[IntrabarOrderGeneration = True];

//Long Only

Inputs:
RewardMultiplier( 2 );

Vars:
EMA( 0 ),
ClickStop( 0 ),
ClickTarget( 0 ),
Stoploss( 0 ),
Target( 0 );

EMA = XAverage( C, 21 );
ClickStop = (High[ 1 ] - Low [ 1 ]) * 4 ;
ClickTarget = ClickStop * RewardMultiplier;

If Barstatus=2 and O < C and L > EMA Then Begin
Buy 1 Contract Next bar at Market;
StopLoss = ClickStop;
Target = ClickTarget;
End;

If Marketposition > 0 Then Begin
setstoploss_pt(StopLoss);
setprofittarget_pt(Target);
end;

//Print( Stoploss );
//Print( Target );

Started this thread Reply With Quote
  #6 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,447 since Apr 2013
Thanks Given: 493
Thanks Received: 1,638

Speculationist,

the way you wrote your code you allow the values to get updated whenever the expression "Barstatus=2 and O < C and L > EMA" is fulfilled i.e. they can change while you are in a position. If you want to prevent the values from changing while you are in a long trade you might want to update the values only while you are not yet long.

Regards,

ABCTG


Speculationist View Post
The Sim mode on my Multicharts has decided to not load data at the moment, however when I print the values of "stoploss" and "target" they seam to be holding the same value as new bars prints.
Am I correct in thinking that this code should be doing the trick?

[IntrabarOrderGeneration = True];

//Long Only

Inputs:
RewardMultiplier( 2 );

Vars:
EMA( 0 ),
ClickStop( 0 ),
ClickTarget( 0 ),
Stoploss( 0 ),
Target( 0 );

EMA = XAverage( C, 21 );
ClickStop = (High[ 1 ] - Low [ 1 ]) * 4 ;
ClickTarget = ClickStop * RewardMultiplier;

If Barstatus=2 and O < C and L > EMA Then Begin
Buy 1 Contract Next bar at Market;
StopLoss = ClickStop;
Target = ClickTarget;
End;

If Marketposition > 0 Then Begin
setstoploss_pt(StopLoss);
setprofittarget_pt(Target);
end;

//Print( Stoploss );
//Print( Target );


Follow me on Twitter Reply With Quote
Thanked by:
  #7 (permalink)
 Speculationist 
Calgary, Alberta/Canada
 
Experience: Advanced
Platform: Tradestation, Multicharts
Broker: IB, AMP
Trading: Stocks, ES, NQ
Posts: 10 since Sep 2012
Thanks Given: 2
Thanks Received: 0

Thanks for the observation, I see what you mean. Should I move the calculations to calculate after a position has been opened?
So include them after Marketposition > 0 ? How else could I do this?

Started this thread Reply With Quote
  #8 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,447 since Apr 2013
Thanks Given: 493
Thanks Received: 1,638

Speculationist,

that would be the opposite of what I wrote in my reply and likely still update the values with every while you are in a position. Allowing the variables to update while you are not yet long will prevent them from changing while you are long and in turn should accomplish what you have in mind.

Regards,

ABCTG


Speculationist View Post
Thanks for the observation, I see what you mean. Should I move the calculations to calculate after a position has been opened?
So include them after Marketposition > 0 ? How else could I do this?


Follow me on Twitter Reply With Quote
  #9 (permalink)
 
SMCJB's Avatar
 SMCJB 
Houston TX
Legendary Market Wizard
 
Experience: Advanced
Platform: TT Stellar & Tradestation
Broker: Primarily Advantage Futures
Trading: Primarily Energy but also a little Equities, Fixed Income, Metals, U308 and Crypto.
Frequency: Many times daily
Duration: Never
Posts: 5,089 since Dec 2013
Thanks Given: 4,440
Thanks Received: 10,283

If (O < C and L > EMA and Position = 0) Then Begin
Buy 1 Contract Next bar at Market;
ClickStop = (High - Low) * 4 ;
ClickTarget = ClickStop * RewardMultiplier;
setstoploss_pt(ClickStop);
setprofittarget_pt(ClickTarget);
End;

Reply With Quote




Last Updated on January 22, 2025


© 2025 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 - Sitemap - Downloads - Top
no new posts