Simulating Stops using 1 min data

Questions about MultiCharts and user contributed studies.
ariliveitup
Posts: 3
Joined: 05 Jun 2010

Simulating Stops using 1 min data

Postby ariliveitup » 23 May 2011

Information:
1. Running a backtest on GC using 1 min bars for 4 years of data
2. Every entry has a pre-decided stop and profit target
3. My logic for simulating stops right now is as follows:
a. if High or Low > or < than Stop Price, Execute Stop next bar market
4. However in real market conditions, I m getting filled tick by tick in my Algo Engine.
5. So in reality, my slippage is going to be 1 to 2 ticks
6. I prefer not to use Intrabar order generation because it will make my strategy logic fairly complicated, because i have multiple time frames and I m using 1m in time frame to construct my own 60 min bars.
7. I was wondering if there is a solution along the lines.
buytocover ("60Min_S_PT") ContractSize shares next bar at 1341.10;

Question:
How do I specify to Multicharts in Easy language that if my stop price is 1340.10 and High of the bar is > 1340.10, fill me at 1340.20 on my stop.


******************************************************************************
Here is the sample code:

Code: Select all

// Shorts Profit Target and Stops
if marketposition = -1 then begin

// Did we hit the profit target
if low < shortProfitTarget then begin
Print("Profit Target Reached for Short Position, Low < ShortProfitTarget: ", shortProfitTarget);

Print("Symbol: ",symbolname, ", Date: ", Date, ", Time: ", Time, ", Open: ", Open, ", High: ", High, ", Low: ", Low, ", Close: ", Close);

Print("Covering short position for the Algo using Profit Target");

buytocover ("60Min_S_PT") ContractSize shares next bar market;
end;

// Did we hit the stop
if high > shortStop then begin
Print("Stop Reached for Short Position, High > ShortStop: ", shortStop);

Print("Symbol: ",symbolname, ", Date: ", Date, ", Time: ", Time, ", Open: ", Open, ", High: ", High, ", Low: ", Low, ", Close: ", Close);

Print("Covering short position for the Algo using Stop Loss");

buytocover ("60Min_S_ST") ContractSize shares next bar market;
end;
end;

// Long Profit Target and Stops
if marketposition = 1 then begin

// Did we hit the profit target
if high > longProfitTarget then begin
Print("Profit Target Reached for Long Position, High > LongProfitTarget: ", longProfitTarget);

Print("Symbol: ",symbolname, ", Date: ", Date, ", Time: ", Time, ", Open: ", Open, ", High: ", High, ", Low: ", Low, ", Close: ", Close);

Print("Covering long position for the Algo using Profit Target");

sell("60Min_L_PT") ContractSize shares next bar market;
end;

// Did we hit the stop
if low < longStop then begin

Print("Stop Reached for Long Position, Low < LongStop: ", longStop);

Print("Symbol: ",symbolname, ", Date: ", Date, ", Time: ", Time, ", Open: ", Open, ", High: ", High, ", Low: ", Low, ", Close: ", Close);

Print("Covering long position for the Algo using Stop Loss");

sell ("60Min_L_ST") ContractSize shares next bar market;
end;
end;

User avatar
Stan Bokov
Posts: 963
Joined: 18 Dec 2009
Has thanked: 367 times
Been thanked: 302 times

Re: Simulating Stops using 1 min data

Postby Stan Bokov » 24 May 2011

7. I was wondering if there is a solution along the lines.
buytocover ("60Min_S_PT") ContractSize shares next bar at 1341.10;
If your stop level is 1341.10, then it's enough for you to write
buytocover ("60Min_S_PT") ContractSize shares next bar at 1341.10;

Just that one line. Could you explain why you need to compare the high of the previous bar with the stop price? IOG is not needed in this case, order will be generated on the next bar after the entry, and will remain open until stop level is hit or the profit target is reached.


Return to “MultiCharts”