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

Profit Targets & Stop Losses - traceable

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

    Profit Targets & Stop Losses - traceable

    I have been working on this next part of my code for a long time and just have not been able to get it figured out. I am at a big stand still - so I decided to come back to the forum to see what we can get worked out.

    Basically, when the order is placed, to entry orders are placed, 2 stop orders are placed, and one limit order is placed to remove a portion of the the trade with a profit. When that happens, the stop for the second entry moves closer to the entry price and then is managed on virtually every bar following that.

    I have looked through all of the great examples that have been given about this and am running into some serious confusion - so much so that I don't really know what questions to even ask - so we will do the best that I can.

    First of all, here is the code that I now have. It is running into errors. When I comment it out, the script compiles without problem.

    Code:
    		protected override void OnExecution(IExecution execution)
    		{
    			TargetPriceLong = Position.AvgPrice + (longSignalHigh - longSignalLow)*TargetPerc;
    			TargetPriceShort = Position.AvgPrice - (shortSignalHigh - shortSignalLow)*TargetPerc;
    			
    			//Setting Long Profit Target
    			if (execution.Order != null
    				&& execution.Order.OrderState == OrderState.Filled)
    				
    				LongLimit = ExitLongLimit(0, true,DefaultQuantity,TargetPriceLong,"LongTarget","LongEntryA");
    			
    			//Setting Short Profit Target
    			if (execution.Order != null
    				&& execution.Order.OrderState == OrderState.Filled)
    				
    				ShortLimit = ExitShortLimit(0, true, DefaultQuantity,TargetPriceShort,"ShortTarget","ShortEntryA");
    The errors are telling me that there are statements expected throughout - but I can't figure out what is wrong with the statements that I currently have. so I figure that is a good place to start.

    In light of the fact that everything needs to be traceable, can somebody help me find out what the errors are?

    It is important that the secondary stop loss does not moved until the initial profit target is hit - and then, it needs to move on the execution of the target and not at the end of the bar. This will be running on small time frames so it is better if it does not wait for the bar to close to insure risk is under control.

    Thank you for your help in advance and I am sure that we will get this thing figured out together.
    Last edited by jg123; 04-02-2014, 03:23 PM.

    #2
    Please Completely disregard this

    I finally figured out what it was - it was a simple } that was being commented out by another section that I was working on. I spent so much time working on it and just could not get it figured out...but now I do. haha

    But there are plenty of other things I am still working on trying to get sorted that I am stuck on but will put them in another thread to keep it all in order.

    Comment


      #3
      Hello jg123,

      What do the errors you are getting say?

      Can we get a screenshot of the errors with the Error column fully expanded so we can read the full error message?
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Hi Chelsea

        Thanks for the reply. I probably didn't get my next post sent before you replied. I apologize for potentially wasting your time on it - but I was able to get it figured out.

        But there are plenty of other issues that I am running into so will let you know.

        Thanks a bunch for your help!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by burtoninlondon, Today, 12:38 AM
        0 responses
        5 views
        0 likes
        Last Post burtoninlondon  
        Started by AaronKoRn, Yesterday, 09:49 PM
        0 responses
        14 views
        0 likes
        Last Post AaronKoRn  
        Started by carnitron, Yesterday, 08:42 PM
        0 responses
        11 views
        0 likes
        Last Post carnitron  
        Started by strategist007, Yesterday, 07:51 PM
        0 responses
        13 views
        0 likes
        Last Post strategist007  
        Started by StockTrader88, 03-06-2021, 08:58 AM
        44 responses
        3,983 views
        3 likes
        Last Post jhudas88  
        Working...
        X