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

Random Entry Strategy (coin toss)

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

    #16
    Originally posted by quantismo View Post
    Hi.... I know this thread was about a random time based entry but this was the closest I could find to what I am trying to do.
    Does anyone know a piece of code that that will allow my all my entries to continually alternate back and forth from LONG TO SHORT LONG TO SHORT LONG TO SHORT and so on and so on.
    Basically even if there was present logic to make a LONG entry and our last entry was already a LONG entry , the algo would wait until there was the logic only to take the SHORT entry next.

    If anyone knows a bit of code that would allow me to do this I would appreciate it.

    Thanks

    Quantismo
    that wouldn't be random....

    but here is what you can start off with. message me privatly if you have no idea how to amend this code for your liking...

    Code:
    			#region random numbers
    			
    						
    			if (Bars.IsFirstBarOfSession)
    			{
    			next = randNum.Next(0,2);	
    			time = randNum.Next(0,21);	
    				Print(next);
    			}
    			#endregion

    next variable will be used for long/short
    time variable will be used to enter long/short at random times

    Code:
    			#region trade logic			
    
    			if (Position.MarketPosition == MarketPosition.Flat&&next == 0&&Times[0][0].TimeOfDay == new TimeSpan(time, 0, 0) )
    			{
    			EnterLongLimit(1,true,Convert.ToInt32(fxToBuy), GetCurrentBid(0), "Target1");		
    			}
    			
                else if(Position.MarketPosition == MarketPosition.Flat&&next == 1 &&Times[0][0].TimeOfDay == new TimeSpan(time, 0, 0) )
    	        {
    			EnterShortLimit(1,true,Convert.ToInt32(fxToBuy), GetCurrentAsk(0), "Target1S");
    	        }			
    				
    			#endregion
    you'll have to change the above market position.flat to long/short to go from one to another etc..think about it

    Comment


      #17
      Originally posted by quantismo View Post
      Hi.... I know this thread was about a random time based entry but this was the closest I could find to what I am trying to do.
      Does anyone know a piece of code that that will allow my all my entries to continually alternate back and forth from LONG TO SHORT LONG TO SHORT LONG TO SHORT and so on and so on.
      Basically even if there was present logic to make a LONG entry and our last entry was already a LONG entry , the algo would wait until there was the logic only to take the SHORT entry next.

      If anyone knows a bit of code that would allow me to do this I would appreciate it.

      Thanks

      Quantismo
      Code:
      			#region entry gates
      			bool LongEntryValid = false;
      			bool ShortEntryValid = false;
      			bool LongEntryAllowed = true;
      			bool ShortEntryAllowed = true;
      			#endregion
      Code:
      			//in OnBarUpdate()
      			if ( /*Long entry conditions met*/ ) LongEntryValid = true;
      			else LongEntryValid = false;
      			if ( /*Short entry conditions met*/ ) ShortEntryValid = true;
      			else ShortEntryValid = false;
      
      			if (LongEntryValid && LongEntryAllowed) {
      			 //Condition the gates
      			 LongEntryAllowed = false; //cannot make another long entry
      			 ShortEntryAllowed = true; //can make short entry
      
      			 //make entry
      			 EnterLong( /*parameters*/ );
      			} else if (ShortEntryValid && ShortEntryAllowed) {
      			 //Condition the gates
      			 LongEntryAllowed = true; //can make long entry
      			 ShortEntryAllowed = false; //cannot make another short entry
      
      			 //make entry
      			 EnterShort( /*parameters*/ );
      			}

      Comment


        #18
        Hello quantismo,

        Thank you for the post.

        Calling EnterLong and EnterShort, alternating between the two will automatically close your position and enter in the other direction. The SampleMACrossover strategy demonstrates that functionality. koganam gives a good example of using booleans to control the flow of logic.

        Please let me know if I can assist further.
        Chris L.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CortexZenUSA, Today, 12:53 AM
        0 responses
        1 view
        0 likes
        Last Post CortexZenUSA  
        Started by CortexZenUSA, Today, 12:46 AM
        0 responses
        1 view
        0 likes
        Last Post CortexZenUSA  
        Started by usazencortex, Today, 12:43 AM
        0 responses
        5 views
        0 likes
        Last Post usazencortex  
        Started by sidlercom80, 10-28-2023, 08:49 AM
        168 responses
        2,265 views
        0 likes
        Last Post sidlercom80  
        Started by Barry Milan, Yesterday, 10:35 PM
        3 responses
        12 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X