Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

problem in OnExecution code block

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    problem in OnExecution code block

    i am having a strange problem in OnExecution for my long long trades, it is processing a code block it shouldn't as it is inside an If statement that equates to false. I checked my brackets and I pretty sure they are all good.


    Code:
    if(this.indPivAverage.ExtrnTrend[0] == 1) // OnExecution long trades
    			{
    				if (pEntry != null && pEntry == execution.Order) // [COLOR="red"]EVEN WHEN THSI IS FALSE[/COLOR]
    				{
    					if 	(	execution.Order.OrderState 	== OrderState.Filled 
    						|| 	execution.Order.OrderState 	== OrderState.PartFilled 
    						|| 	(execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0)
    						)
    					{
    						// Stop order
    						pStop = ExitLongStop(0, true, execution.Order.Filled, Array.FindLast(pivotsOnly, k => k <= pEntry.AvgFillPrice) - stop * TickSize , "Stop of Long", "pEntry");
    						
    						// Resets the entryOrder object to null after the order has been filled
    						if (execution.Order.OrderState != OrderState.PartFilled)
    						{
    							
    					
    							if(hPiv-lPiv >= 50 * TickSize)
    								{
    								target = lPiv + 2.0/3.0 * (hPiv-lPiv);
    								}
    							else if(hPiv-lPiv >= psb*TickSize)
    								{
    								target = hPiv - Math.Max(2*TickSize,(hPiv-lPiv)*0.1);
    								}
    							else if(hPiv-lPiv < psb*TickSize)
    								{
    								target = longLevels[longLevels.FindIndex(o => o > hPiv)];
    								}
    								
    							if(positionWatchLong != true)
    							{
    								longBar 			= CurrentBar;
    								pStopPrice			= pStop.StopPrice;
    								longPriceWatch		= pEntry.AvgFillPrice;
    								positionWatchLong	= true;
    								targetWatch			= target;
    							}
    							
    							pEntry 			= null;
    							fillBar			= CurrentBar; // for the drawling target
    							longPrice 		= pEntry.AvgFillPrice; // [COLOR="Red"]I AM GETTING AN ERROR HERE AS pEntry is null[/COLOR]
    							
    								
    							tradeHigh		= 0;
    						}
    					}
    				}
                       }

    #2
    Hello GKonheiser,

    Thank you for your post.

    Try using Print() to print the name of the execution to verify. For example:
    Code:
    if(this.indPivAverage.ExtrnTrend[0] == 1) // OnExecution long trades
    			{
    				if (pEntry != null && pEntry == execution.Order) 
    				{
    				    Print("Block processing for " + execution.Name.ToString() + " at " + Time[0].ToString());
    Please let me know if you are still seeing unexpected calls.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by haas88, 03-21-2024, 02:22 AM
    19 responses
    220 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by ZeroKuhl, Yesterday, 04:31 PM
    4 responses
    29 views
    0 likes
    Last Post ZeroKuhl  
    Started by cupir2, Yesterday, 07:44 PM
    3 responses
    21 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by reynoldsn, Yesterday, 07:26 PM
    2 responses
    16 views
    0 likes
    Last Post reynoldsn  
    Started by MartinT, 05-17-2023, 06:00 AM
    18 responses
    175 views
    0 likes
    Last Post flybuzz
    by flybuzz
     
    Working...
    X