Problem with TradingStrategy and barstatus

Questions about MultiCharts and user contributed studies.
KhaosTrader
Posts: 186
Joined: 10 May 2012
Has thanked: 14 times
Been thanked: 11 times

Problem with TradingStrategy and barstatus

Postby KhaosTrader » 19 Aug 2012

Hi,

Below is some strategy code that should be entering trades more often than it is. It is trading aapl, I have included the strategy on both 5 min and 60 min aapl charts with the areas where it should be entering trades circled in red, with the underlined qualified entry bars...

here is the code:

Code: Select all


variables:
TickSize (MinMove/PriceScale);



[IntrabarOrderGeneration = true]


// open new positions


if (MarketPosition = 0 and barstatus(1) = 2 and Low >= Low[1] and High >= High[1]) then begin
Buy ("Enter Long") 300 Shares Next Bar At high stop;
end;



Value1 = Text_New(Date, Time, Low-TickSize, NumToStr(CurrentShares, 0));

// manage open orders

if MarketPosition = 1 then begin
Sell("Profit Target") 300 Shares Next Bar at (EntryPrice + 1) Limit;
Sell("Stop Loss") 300 Shares Next Bar at (EntryPrice-1) Stop;
end;

***Charts are attached, one is a 60 min and the other is a 5 minute chart.
Attachments
StratProb3.png
(47.48 KiB) Downloaded 377 times
StratProb2.png
(39.77 KiB) Downloaded 377 times

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Problem with TradingStrategy and barstatus

Postby Henry MultiСharts » 20 Aug 2012

Hello KhaosTrader,

The conditions for generating the order are met on the highlighted bars, though the order cannot be filled on the opening tick of the next bar because price condition "Buy Next Bar At high stop" is not met. Opening price of subsequent bars is lower than high of the previous bar, order is not filled and is cancelled as the conditions for generating the order are no longer met (Calculation on historical data. IOG enabled. No Bar Magnifier. The script is calculated four times on OHLC. It is considered that all prices were within the bar (Price movement assumption is used). Order filled on any price within the bar). You can use the Print statement in your code to check it.

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Problem with TradingStrategy and barstatus

Postby TJ » 20 Aug 2012

with [IntrabarOrderGeneration = true],
if the order was not filled on the 1st tick of the new bar,

Code: Select all

Buy Next Bar At high
will need to be re-coded to

Code: Select all

Buy Next Bar At high[1]

KhaosTrader
Posts: 186
Joined: 10 May 2012
Has thanked: 14 times
Been thanked: 11 times

Re: Problem with TradingStrategy and barstatus

Postby KhaosTrader » 21 Aug 2012

Ok I am experimenting with workarounds and will post my progress within the next couple of days...


Return to “MultiCharts”