How to avoid signal order next bar

Questions about MultiCharts and user contributed studies.
User avatar
CrazyNasdaq
Posts: 318
Joined: 02 Sep 2009
Location: ITALY
Has thanked: 97 times
Been thanked: 86 times

How to avoid signal order next bar

Postby CrazyNasdaq » 02 Jul 2014

Hi, i'm having a problem with a signal which generates a second order on next bar.
Surely I'm making something wrong, but I don't know what.
The problem is this:
Suppose that I've a 60 min chart and a momentum on open bar of this 60min chart.
If the condition of the momentum is met, the signal must Buy or sell at a specified price.
I'm forced by the script to use "Buy /Sell Next bar at price X".
This way the order could be executed even this bar (with IOG enabled), and this is good, but if it is executed this bar and it reaches in this bar the profit target or the Stop Loss target it exits the position how it should.
The problem is on next bar on which the signal generates a new order with relative Profit and Stop Loss, and I want to avoid this.
Here is an example of what I mean:

Code: Select all

[IntrabarOrderGeneration = true]

Inputs:
Length.Momentum(14),
Price.Momentum(open),
N.Contracts(1),
N.Ticks.Profit(10),
N.Ticks.Stop(10);

vars:
H1(0),
L1(0),
H2(0),
L2(0),
H3(0),
L3(0),
M1(0),
M2(0),
M3(0),
var1(0),
Last.Low(0),
Last.High(0);

H3 = High[2]; //High 2 candles ago
L3 = Low[2]; //Low 2 candles ago

H2 = High[1]; //High prior candle
L2 = Low[1]; //Low prior candle

H1 = High; //High last candle
L1 = Low; //Low last candle

var1 = momentum(Price.momentum, Length.Momentum); //momentum OPEN
M3 = var1[2]; // momentum 2 candles ago
M2 = var1[1]; // momentum prior candle
M1 = var1; // actual momentum


//******************************
// ******** LONG conditions ******

condition11 = L3 > L2 and M3 > M2;
condition12 = L2 < L1 and M2 > M1;
condition13 = condition11 and condition12;

if condition13 then begin
Last.High = High + (1*(minmove/pricescale)); //Identify the MAX for the breakout Entry

END; // : END if condition13 then begin

// *** LONG Order ***
if condition13 and marketposition = 0 then begin
Buy ("Buy Long 1") N.contracts contracts next bar at (High[1] + (1*(minmove/pricescale)))stop;
end; // : END LONG order


// ** STOP PROFIT and STOP LOSS Orders ****
SetStopposition;
SetStopLoss(((bigpointvalue*(minmove/pricescale))*N.ticks.Stop));
SetProfitTarget(((bigpointvalue*(minmove/pricescale))*N.ticks.profit));


Image

How can I avoid these repeated orders ?
If the condition is met and the order is filled and the position is closed even in within this bar, it should not generates a new order next bar.
How to achieve this ?
Can someone help me or suggest something.
I'm relatively new to signal. I've always practice discretionary trading with my properties indicators, so I'm not so skilled with signal orders.
Thanks

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: How to avoid signal order next bar

Postby JoshM » 06 Jul 2014

If you add a true/false variable to determine whether the strategy is allowed to trade or not, this behaviour can be prevented.

For example, something like:

Code: Select all

Variables:
okayToTrade(false),
prevMP(0);

// Determine when the strategy is allowed to take its trades,
// for example reset the variable once per day:
if (Date <> Date[1]) then
okayToTrade = true;

// Set variable to false if position is opened
if (prevMP <> MarketPosition(0) and MarketPosition(0) <> 0) then
okayToTrade = false;

if (okayToTrade = true) then begin

// submit the orders here

end;

prevMP = MarketPosition(0);

User avatar
CrazyNasdaq
Posts: 318
Joined: 02 Sep 2009
Location: ITALY
Has thanked: 97 times
Been thanked: 86 times

Re: How to avoid signal order next bar

Postby CrazyNasdaq » 06 Jul 2014

If you add a true/false variable to determine whether the strategy is allowed to trade or not, this behaviour can be prevented.
Thanks JoshM.
It's a good suggestion and I think it will work

Thanks again


Return to “MultiCharts”