Same Strategy, Same Market, Same Time = Different trades! - futures io
futures io futures trading



Same Strategy, Same Market, Same Time = Different trades!


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one MXASJ with 13 posts (0 thanks)
    2. looks_two RJay with 4 posts (1 thanks)
    3. looks_3 mrticks with 2 posts (0 thanks)
    4. looks_4 max-td with 2 posts (1 thanks)
    1. trending_up 7,899 views
    2. thumb_up 2 thanks given
    3. group 0 followers
    1. forum 22 posts
    2. attach_file 2 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

Same Strategy, Same Market, Same Time = Different trades!

(login for full post details)
  #1 (permalink)
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 799 received

Hey All,

I've been sim trading a strategy that calls an ATM when getting buy or sell signals, and last night copied it and took out the buy/sell actions and replaced them with playsound and drawarrow commands so it was a "signal only" strat.

I then ran both on live ES data, using signals generated by the "signal only" strat to manually enter trades in one of my brokerage accounts. All in a days work.

BUT... the "signal only" strat was generating calls that the sim trader never took, and in some cases sim trader kicked in a few bars later. The "signal only" strat appeared to follow the conditions in the strat perfectly, while the one that does the buy/sell was less predictable.

Any ideas on where I should look for errors?

FWIW the ATM call strategy is cut-and-paste from the factory example.

Started this thread Reply With Quote

Journal Challenge February 2021 results (so far):
Competing for $1500 in prizes from Topstep
looks_oneSBtrader82 's Trading Journalby SBtrader82
(167 thanks from 31 posts)
looks_twoJust BEING a Trader: Letting Go!!by iqgod
(116 thanks from 33 posts)
looks_3Wisdom is Emptinessby Mtype
(68 thanks from 25 posts)
looks_4Deetee’s DAX Trading Journal (time based)by Deetee
(31 thanks from 17 posts)
looks_5Journal for peanuts1956by peanuts1956
(23 thanks from 13 posts)
 
 
(login for full post details)
  #2 (permalink)
Frankfurt
 
Experience: Intermediate
Platform: NinjaTrader
Trading: FGBL 6E B4
 
max-td's Avatar
 
Posts: 1,754 since Jun 2009
Thanks: 2,309 given, 924 received

hi,
i try to understand : you have

1) your trading-signals/logic coded as an indicator to show arrows in the chart + give a sound

and

2) your trading-signals/logic as a strategy to start sim/live -trades

these 2 behave different.

right till here ?

max-td
Reply With Quote
 
(login for full post details)
  #3 (permalink)
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 799 received


No they are both strategies. The difference is instead of buy/sell as an action its playsound/draw bar.

Started this thread Reply With Quote
 
(login for full post details)
  #4 (permalink)
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 799 received

The sound and draw one:

///</summary>
protectedoverridevoid OnBarUpdate()
{
///GO LONG: Conditions followed by ATM Strategy execution.
if (VSuperTrend(14, TradingStudies.NinjaScript.Utility.MovingAverageType.SMA, 2.618, 14, TradingStudies.NinjaScript.Utility.SuperTrendMode.ATR).Signal[0] == 1
&& (ATRratio(14, 7, 1).Ratio[0] >= 1)
&& (ADXVMA_sharky_paint(
6, true).Main[0] > ADXVMA_sharky_paint(6, true).Main[1])
&& (ECO2New2(
7, 4, 21).Main[0] > ECO2New2(7, 4, 21).Signal[0])
&& Rising(ECO2New2(
7, 4, 21).Main) == true)

{
DrawArrowUp(
"My up arrow" + CurrentBar, true, 0, High[0]+TickSize, Color.Green);
PlaySound(
@"C:\Program Files\NinjaTrader 6.5\sounds\LongES.wav");
Log(
"ES Sound Only LONG signal", LogLevel.Information);

}
///GO SHORT: Conditions followed by ATM Strategy execution.

etc etc etc

Started this thread Reply With Quote
 
(login for full post details)
  #5 (permalink)
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 799 received

The call ATM one has this instead of the drawarrowup, etc:

{
// ATM Strategy code cut-and-paste from NT
// Make sure this strategy does not execute against historical data
if (Historical)
return;
 
// Submits an entry limit order at the current low price to initiate an ATM Strategy if both order id and strategy id are in a reset state
// **** YOU MUST HAVE AN ATM STRATEGY TEMPLATE NAMED 'ES 2 w BE and Trail' CREATED IN NINJATRADER (SUPERDOM FOR EXAMPLE) FOR THIS TO WORK ****
if (orderId.Length == 0 && atmStrategyId.Length == 0 && Close[0] > Open[0])
{
atmStrategyId = GetAtmStrategyUniqueId();
orderId = GetAtmStrategyUniqueId();
AtmStrategyCreate(Action.Buy, OrderType.Market,
0, 0, TimeInForce.Day, orderId, "ES 2 w BE and Trail", atmStrategyId);

}
 
// Check for a pending entry order
if (orderId.Length > 0)
{
string[] status = GetAtmStrategyEntryOrderStatus(orderId);

// If the status call can't find the order specified, the return array length will be zero otherwise it will hold elements
if (status.GetLength(0) > 0)
{
// Print out some information about the order to the output window
Print("The entry order average fill price is: " + status[0]);
Print(
"The entry order filled amount is: " + status[1]);
Print(
"The entry order order state is: " + status[2]);
// If the order state is terminal, reset the order id value
if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected")
orderId =
string.Empty;
}
}
// If the strategy has terminated reset the strategy id
elseif (atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)
atmStrategyId =
string.Empty;
 
if (atmStrategyId.Length > 0)
{
// You can change the stop price
if (GetAtmStrategyMarketPosition(atmStrategyId) != MarketPosition.Flat)
AtmStrategyChangeStopTarget(
0, Low[0] - 3 * TickSize, "STOP1", atmStrategyId);
// Print some information about the strategy to the output window
Print("The current ATM Strategy market position is: " + GetAtmStrategyMarketPosition(atmStrategyId));
Print(
"The current ATM Strategy position quantity is: " + GetAtmStrategyPositionQuantity(atmStrategyId));
Print(
"The current ATM Strategy average price is: " + GetAtmStrategyPositionAveragePrice(atmStrategyId));
Print(
"The current ATM Strategy Unrealized PnL is: " + GetAtmStrategyUnrealizedProfitLoss(atmStrategyId));
}

Started this thread Reply With Quote
 
(login for full post details)
  #6 (permalink)
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 799 received

So the the conditions that lead to an an action are the same. Is there anything in the call ATM code... wait... what's that close[0]>open[0]?

Started this thread Reply With Quote
 
(login for full post details)
  #7 (permalink)
Hartford, CT. USA
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG, Kinetick
Trading: RTY
 
RJay's Avatar
 
Posts: 688 since Jun 2009
Thanks: 747 given, 780 received

Hi MXASJ,

Are both strategies running on the same chart or different charts?

RJay

Reply With Quote
 
(login for full post details)
  #8 (permalink)
Frankfurt
 
Experience: Intermediate
Platform: NinjaTrader
Trading: FGBL 6E B4
 
max-td's Avatar
 
Posts: 1,754 since Jun 2009
Thanks: 2,309 given, 924 received

i know from some examples where the printed values of indicators hasnt been the same as the values using this indicator in a strategy - always because of a special + unique coding-problem.
so your arrow+sound is a plotting-thing + order-execution is a strategy-thing.
i see you use the ADXVMA -- thats one of the examples i am talking about -- i had trouble too with that some time ago.
here is a link -- have a look + test it .

ADXVMA strategy problem? - NinjaTrader Support Forum

Indicator output is different when invoked by strategy - NinjaTrader Support Forum

good luck --- and report please

max-td
Reply With Quote
The following user says Thank You to max-td for this post:
 
(login for full post details)
  #9 (permalink)
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 799 received

vielen danke max. Before I get too carried away what would the Close[0]>Open[0] thing in the ATM start do? Only long after a postive bar?

"if (orderId.Length == 0 && atmStrategyId.Length == 0 && Close[0] > Open[0])" is the example ATM strat code from NT (what I'm using).

I'll try the tips NTJosh mentioned as well.

Also looking at splitting the strat (actually the ATM it fires) into two... europe open and NYSE open. Wider stops on the NYSE open.

But now I need to sleep. Strat running on sim account. G'nite!



Started this thread Reply With Quote
 
(login for full post details)
  #10 (permalink)
Florida
 
Experience: Intermediate
Platform: NT7
Trading: CL, NQ, NG
 
Posts: 469 since Jun 2009
Thanks: 1,401 given, 402 received



MXASJ View Post
...
"if (orderId.Length == 0 && atmStrategyId.Length == 0 && Close[0] > Open[0])" is the example ATM strat code from NT (what I'm using)....


I believe those tell you orderId.Length == 0 means no pending order

atmStrategyId.Length== 0 means not in a current trade

if you find something different, let us know
thanks
kz

Reply With Quote
 
(login for full post details)
  #11 (permalink)
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 799 received

I looked at the original "exampleATMstrategy" and think I found the problem. Recoded, compiled, and running against a market replay file now.

The strats were running on different but identical charts, RJay.

I'll tell ya... losing real money is a great motivator for learning more about Ninjascript.

I'll tackle the ADXVMA max pointed out next...

Started this thread Reply With Quote
 
(login for full post details)
  #12 (permalink)
Hartford, CT. USA
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG, Kinetick
Trading: RTY
 
RJay's Avatar
 
Posts: 688 since Jun 2009
Thanks: 747 given, 780 received


MXASJ View Post
I looked at the original "exampleATMstrategy" and think I found the problem. Recoded, compiled, and running against a market replay file now.

The strats were running on different but identical charts, RJay.

I'll tell ya... losing real money is a great motivator for learning more about Ninjascript.

I'll tackle the ADXVMA max pointed out next...

The reason I asked this about multiple charts, is be sure that all charts have the exact same historical start point.

If they start at different times, I find charts don't match up.

RJay

Reply With Quote
 
(login for full post details)
  #13 (permalink)
Arcata, CA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: index futures, oil
 
Saroj's Avatar
 
Posts: 486 since Jun 2009
Thanks: 232 given, 413 received


RJay View Post
The reason I asked this about multiple charts, is be sure that all charts have the exact same historical start point.

If they start at different times, I find charts don't match up.

RJay

RJay, is that by specifying the same number of bars or the same number of days or either? (in the Format Data Series Dialogue Box) or am I totally on the wrong track?

Reply With Quote
 
(login for full post details)
  #14 (permalink)
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 799 received

Well its not quite there yet. Attached two photos... one of the strat executing the ATM and one of the strat executing draw arrow. There are four instances where the strat with the ATM "missed" buy signals and one instance where it did a "buy" when it should not have.

When those two strats run live against incoming data, the indicators look exactly the same.

Attached Thumbnails
Click image for larger version

Name:	ES 09-09  7_17_2009 (5 Min) AROOWS.jpg
Views:	82
Size:	145.0 KB
ID:	801   Click image for larger version

Name:	ES 09-09  7_17_2009 (5 Min) STRAT.jpg
Views:	65
Size:	98.0 KB
ID:	802  
Started this thread Reply With Quote
 
(login for full post details)
  #15 (permalink)
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 799 received

In a way it was good to be out of some of that chop... I just need to figure out why the code does not work the same between both strats.

Go Long ATM:
// ATM Strategy code cut-and-paste from NT
// Make sure this strategy does not execute against historical data
if (Historical)
return;
 
// Submits an entry limit order at the current low price to initiate an ATM Strategy if both order id and strategy id are in a reset state
// **** YOU MUST HAVE AN ATM STRATEGY TEMPLATE NAMED 'ES 2 w BE and Trail' CREATED IN NINJATRADER (SUPERDOM FOR EXAMPLE) FOR THIS TO WORK ****
// in the line below I've deleted && Close[0] > Open[0] from the default sampleATMstrategy code
if (orderId.Length == 0 && atmStrategyId.Length == 0 )
{
atmStrategyId = GetAtmStrategyUniqueId();
orderId = GetAtmStrategyUniqueId();
AtmStrategyCreate(Action.Buy, OrderType.Market,
0, 0, TimeInForce.Day, orderId, "ES 2 w BE and Trail", atmStrategyId);

}
 
// Check for a pending entry order
if (orderId.Length > 0)
{
string[] status = GetAtmStrategyEntryOrderStatus(orderId);

// If the status call can't find the order specified, the return array length will be zero otherwise it will hold elements
if (status.GetLength(0) > 0)
{
// Print out some information about the order to the output window
Print("The entry order average fill price is: " + status[0]);
Print(
"The entry order filled amount is: " + status[1]);
Print(
"The entry order order state is: " + status[2]);
// If the order state is terminal, reset the order id value
if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected")
orderId =
string.Empty;
}
}
// If the strategy has terminated reset the strategy id
elseif (atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)
atmStrategyId =
string.Empty;
 
if (atmStrategyId.Length > 0)
{
// You can change the stop price
if (GetAtmStrategyMarketPosition(atmStrategyId) != MarketPosition.Flat)
AtmStrategyChangeStopTarget(
0, Low[0] - 3 * TickSize, "STOP1", atmStrategyId);
// Print some information about the strategy to the output window
Print("The current ATM Strategy market position is: " + GetAtmStrategyMarketPosition(atmStrategyId));
Print(
"The current ATM Strategy position quantity is: " + GetAtmStrategyPositionQuantity(atmStrategyId));
Print(
"The current ATM Strategy average price is: " + GetAtmStrategyPositionAveragePrice(atmStrategyId));
Print(
"The current ATM Strategy Unrealized PnL is: " + GetAtm

Started this thread Reply With Quote
 
(login for full post details)
  #16 (permalink)
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 799 received

Go long arrow:

DrawArrowUp("My up arrow" + CurrentBar, true, 0, High[0]+TickSize, Color.Green);
// delete to enable PlaySound(@"C:\Program Files\NinjaTrader 6.5\sounds\LongES.wav");
// delete to enable Log("ES Sound Only LONG signal", LogLevel.Information);


Started this thread Reply With Quote
 
(login for full post details)
  #17 (permalink)
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 799 received

Mission today for me:

1. Compare each strat's code once again, line by line.
2. Run both on the same chart using Market Replay 1x speed.
3. Work on hard coding an "ATM like" exit strategy as Mike suggested weeks ago . I've started that already on a strat I use on FESX, but struggling with how to "tighten" stops after trailing for a while.

It's 9am where I live, which gives me 5 hours until FESX opens. Let the Games begin!

Started this thread Reply With Quote
 
(login for full post details)
  #18 (permalink)
Hartford, CT. USA
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG, Kinetick
Trading: RTY
 
RJay's Avatar
 
Posts: 688 since Jun 2009
Thanks: 747 given, 780 received


Saroj View Post
RJay, is that by specifying the same number of bars or the same number of days or either? (in the Format Data Series Dialogue Box) or am I totally on the wrong track?

Saroj,

As a test, open charts with market data disconnected. Open and set up charts with same start date or bar #.

let charts load from resident historic data.

now connect market data source. after load is complete, run comparison testing.

RJay

Reply With Quote
The following user says Thank You to RJay for this post:
 
(login for full post details)
  #19 (permalink)
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 799 received


MXASJ View Post
Mission today for me:

1. Compare each strat's code once again, line by line.
2. Run both on the same chart using Market Replay 1x speed.
3. Work on hard coding an "ATM like" exit strategy as Mike suggested weeks ago . I've started that already on a strat I use on FESX, but struggling with how to "tighten" stops after trailing for a while.

It's 9am where I live, which gives me 5 hours until FESX opens. Let the Games begin!

Just to update this thread. My problem was solved with Action #1 above. A single typo in my strat code had it trading against an indicator parameter that was different than the plotted parameter.

I've found the bug, and it was me.

On the ATM-like hard code, I'm still playing around with it. To be honest the only reason for it seems to be the issue of backtesting using data from different time frames. Important, but I need to prioritize what I need to do in NT.

Started this thread Reply With Quote
 
(login for full post details)
  #20 (permalink)
Hartford, CT. USA
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG, Kinetick
Trading: RTY
 
RJay's Avatar
 
Posts: 688 since Jun 2009
Thanks: 747 given, 780 received


MXASJ View Post
Just to update this thread. My problem was solved with Action #1 above. A single typo in my strat code had it trading against an indicator parameter that was different than the plotted parameter.

I've found the bug, and it was me.

On the ATM-like hard code, I'm still playing around with it. To be honest the only reason for it seems to be the issue of backtesting using data from different time frames. Important, but I need to prioritize what I need to do in NT.

MXASJ,

Good for you!!!

I think it is very important that everyone learn how to test and tweak your own programs.

Personally, I am glad I took the time to learn how to do this.

I usually tweak nearly every indicator I test or use.

RJay

Reply With Quote
 
(login for full post details)
  #21 (permalink)
Dublin, Ireland.
 
Experience: Advanced
Platform: NinjaTrader, TOS, Multicharts, Open Source various
Trading: FDAX, cable/yen, FX, options on commodities
 
mrticks's Avatar
 
Posts: 67 since Jun 2009
Thanks: 16 given, 10 received


MXASJ View Post
Just to update this thread. My problem was solved with Action #1 above. A single typo in my strat code had it trading against an indicator parameter that was different than the plotted parameter.

I've found the bug, and it was me.

On the ATM-like hard code, I'm still playing around with it. To be honest the only reason for it seems to be the issue of backtesting using data from different time frames. Important, but I need to prioritize what I need to do in NT.


Hi MXASJ - Any chance you could post the code from the completed strategy? I'm trying to make one work with long and short entry conditions but I keep getting errors in the log, then it stops running. I've added in TraceOrders = true ; and print () statements everywhere then viewed the output window but it doesn't show where it falls down as the errors all happen at once. I keep getting method errors that say orderid and strategy id don't exist. Am working on it now but have spent a long time at it.

If you could put up the code with an entry condtion calling on an ATM I'd really appreciate it.


Thanks,

Gavin.

Reply With Quote
 
(login for full post details)
  #22 (permalink)
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 799 received

Hi Gavin,

Man that seems like a long time ago... I actually don't have that strat any more and I've moved all my development over to NT7. Also, I haven't been using strats to fire ATM strategies in quite some time.

Where are you stuck?

The basic logic was like this pseudo code:

//Go long

If (Its going up!
&& marketposition is flat)
Launch MyLongAtm

//Go short

If (Its tanking!
&& marketposition is flat)
Launch MyShortATM

My thing was based on the sample ATM strategy code at the Ninja site.

Started this thread Reply With Quote
 
(login for full post details)
  #23 (permalink)
Dublin, Ireland.
 
Experience: Advanced
Platform: NinjaTrader, TOS, Multicharts, Open Source various
Trading: FDAX, cable/yen, FX, options on commodities
 
mrticks's Avatar
 
Posts: 67 since Jun 2009
Thanks: 16 given, 10 received


MXASJ View Post
Hi Gavin,

Man that seems like a long time ago... I actually don't have that strat any more and I've moved all my development over to NT7. Also, I haven't been using strats to fire ATM strategies in quite some time.

Where are you stuck?

The basic logic was like this pseudo code:

//Go long

If (Its going up!
&& marketposition is flat)
Launch MyLongAtm

//Go short

If (Its tanking!
&& marketposition is flat)
Launch MyShortATM

My thing was based on the sample ATM strategy code at the Ninja site.

Thanks for the reply. I stripped down the NT6 sample ATM cs and now I only have one error which is "ATMstrategycancelorder" orderId does not exist.

I'll keep at it, will get there eventually, have spent a log time on it though.

Have a good weekend.

Reply With Quote


futures io Trading Community Platforms and Indicators NinjaTrader > Same Strategy, Same Market, Same Time = Different trades!


Last Updated on January 29, 2010


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Journal Challenge w/$1500 prizes from Topstep!

February
 

Battlestations! Show us your trading desk - $1,500 in prizes!

March
 

Call Option Buying: The New Pain Trade? w/Carley Garner

Elite only
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts