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

strategy problem - wait x bars if winner/loser

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

    strategy problem - wait x bars if winner/loser

    Hi,

    I would really appreciate some help on this attached strategy. I've added notes in the code.

    We have a simple entry: a green bar.

    Then, the idea is that if the last trade is a winner, we wait 5 bars before the next entry is allowed. If the last trade is a loser, we wait 20 bars before the next trade is allowed.

    As it is, the strategy doesn't wait and continues to enter on the next green bar regardless of whether the last trade was a winner or a loser.

    I think I have a lot of things right in the code, but since I'm a novice, I have something fundamental missing, or in the wrong order, or I need to nest some if's...

    Any hints would be greatly appreciated

    thanks,
    David
    Attached Files
    Last edited by trader3000a; 02-25-2023, 11:15 AM.

    #2
    Hello trader3000a,

    From what I can see you are using BarsSinceExitExecution, if you are not seeing this work as expected you need to use prints to find out why.

    You are printing the profit but you are not printing the values you use in all of your conditions.

    You also have a first entry condition that can happen any time the Close is greater than the open. If you are using that as a starting trade I would suggest to remove that and instead use BarsSinceExitExecution value of -1 to know an exit was not found to know to place an initial entry.

    https://ninjatrader.com/support/help...lightsub=BarsS inceExitExecution
    Method Return Value
    An int value that represents a number of bars. A value of -1 will be returned if a previous exit does not exist.​
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by rbeckmann05, Yesterday, 06:48 PM
    1 response
    12 views
    0 likes
    Last Post bltdavid  
    Started by llanqui, Today, 03:53 AM
    0 responses
    6 views
    0 likes
    Last Post llanqui
    by llanqui
     
    Started by burtoninlondon, Today, 12:38 AM
    0 responses
    10 views
    0 likes
    Last Post burtoninlondon  
    Started by AaronKoRn, Yesterday, 09:49 PM
    0 responses
    15 views
    0 likes
    Last Post AaronKoRn  
    Started by carnitron, Yesterday, 08:42 PM
    0 responses
    11 views
    0 likes
    Last Post carnitron  
    Working...
    X