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

Increase Position Size After Loss

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

    Increase Position Size After Loss

    I can't figure this out. I've uploaded the strategy. I need it to Increase Position Size after each Loss. You'll find my attempt in the section

    Code:
    //MANAGE LOSSES
    	#region LOSSES MAnagement
    			//STEP 1: Reset the trade Counter at Beginning of NEW Session
    				if (Bars.FirstBarOfSession && FirstTickOfBar)
    				{
    					previousLossTrade = 0;
    					priorSessionTrades = Performance.AllTrades.Count;
    				}
    			//STEP 2: Here, Performance.AllTrades.Count - priorSessionTrades checks to make sure there have been 1 trades today.
    					//   priorNumberOfTrades makes sure this code block only executes when a new trade has finished.
    			if ( FirstTickOfBar && (Performance.AllTrades.Count - priorSessionTrades) >= 1 && Performance.AllTrades.Count != priorNumberOfTrades)
    			{
    				// Reset the counter.
    				previousLossTrade = 0;
    					
    				// Set the new number of completed trades.
    				priorNumberOfTrades = Performance.AllTrades.Count;
    			
    				//Look at Last Trade (index 1) Performance
    				Trade lastTrade = Performance.AllTrades[Performance.AllTrades.Count - 1];
    				lastProfit = lastTrade.ProfitPoints;
    				//If the trade's profit is greater than Set Target, RESET COUNTER. IF Less than Loss Target, Add one.
    					if (lastTrade.ProfitPoints >= 2)
    						previousLossTrade = 0;
    					else if (lastTrade.ProfitPoints <= -1.8)
    						previousLossTrade++; 
    						
    					Print("The last trade's profitLoss is " + lastProfit);
    					Print("Last Trade Won/Loss: " + previousLossTrade);
    			}
    			
    		//REGULAR Position Size: If Previous Trade Didn't Lose, Go for Regular Profit Target and Position Size
    						if(previousLossTrade == 0)
    							{
    								tradeLotSize = scalpLotSize;
    								takeProfit = profitTarget;		
    							}	
    					//RECOVERY TRADE Size:: If Only One Previous LOSS occurred, Increase Size and Target to Recover
    						else if(previousLossTrade == 1)
    							{
    								tradeLotSize = scalpLotSize * 3;
    								takeProfit = recoveryTarget;		
    							}	
    					//2nd RECOVERY TRADE Size:: If Two Previous LOSSes occurred, Increase Size and Target to Recover
    						else if(previousLossTrade == 2)
    							{
    								tradeLotSize = scalpLotSize * 6;
    								takeProfit = recoveryTarget;		
    							}
    			//PRINT Current Position Size after High Volume APpears. So you always know what the Next Trade size will be in OutPut Window
    					if(Volume[0] >= Volume[1])
    					{	Print("NEXT POSITION SIZE " + tradeLotSize);	}			
    				
    	#endregion
    What's actually happening is that the Position Size stays the Same after each Loss. I don't know why.

    Please Help.

    Thank You
    Attached Files

    #2
    Hello,

    I believe this may be due to the logic you are using. I tested the script on the ES 12-15 on a 1 minute chart and see the prints:

    NEXT POSITION SIZE 1000
    and
    NEXT POSITION SIZE 3000

    If the variable in question is the one you are printing or tradeLotSize, I do see this being updated and changed.

    Can you confirm, is this the correct variable in question and are you not seeing it increment? if not can you provide more specific details on exactly which values do not increment?

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by pechtri, 06-22-2023, 02:31 AM
    6 responses
    116 views
    0 likes
    Last Post Nyman
    by Nyman
     
    Started by birdog, 01-25-2023, 08:10 PM
    2 responses
    158 views
    1 like
    Last Post RickAce
    by RickAce
     
    Started by stafe, 04-15-2024, 08:34 PM
    12 responses
    59 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by benmarkal, Today, 12:52 PM
    0 responses
    5 views
    0 likes
    Last Post benmarkal  
    Started by Tim-c, Today, 03:54 AM
    3 responses
    13 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Working...
    X