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 Using Custom Methods from Addon

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

    Strategy Using Custom Methods from Addon

    I am creating a custom partial class to handle to hold some code I will be reusing through out several strategies. But when i call the custom methods, it seems the strategy does not execute the code. No orders are placed and I do not get any errors in the log nor output screen.

    snippet from my addon file:
    PHP Code:
    namespace NinjaTrader.NinjaScript.Strategies
    {
        public 
    partial class RemoteControl Strategy
        
    {
            
            
    // This can be accessed from within another addon with MySharedMethodsAddonExample.SharedDouble
            // or can be accessed from any script using NinjaTrader.NinjaScript.AddOns.MySharedMethods.SharedDouble
            
            
    public static DateTime lastWriteAlive
            
    getset; }

            public 
    void BuyBid_rc(int ordersizedouble Bidstring SignalName)
            {
            
    EnterLongLimit(ordersize,BidSignalName);        
            }
            
            public 
    void SellAsk_rc(int ordersizedouble Askstring SignalName)
            {
            
    EnterShortLimit(ordersize,Ask,SignalName);
            }
        
        } 
    Snippet from my strategy referencing the custom partial class

    PHP Code:
    private RemoteControl RC;
    RC    = new RemoteControl();

     if (
    GRUp)
             {
             if (!(
    DrawObjects["DotUp" CurrentBar] != null && DrawObjects["DotUp" CurrentBar].GetType().Name == "Dot"))
                    
    Draw.Dot(this"DotUp" CurrentBartrue0GetCurrentAsk(), Brushes.Blue);
                
             
                 
    Draw.VerticalLine(this"Vline" CurrentBar0Brushes.LightBlue);
               
    // EnterLong(0,orderSize,"G2Up");
                 
    RC.BuyBid_rc(orderSize,GetCurrentBid(),"G2Up");
             }
             
             
               if (
    GRDn)
                {
                if (!(
    DrawObjects["DotDn" CurrentBar] != null && DrawObjects["DotDn" CurrentBar].GetType().Name == "Dot"))
                         
    Draw.Dot(this"DotDn" CurrentBartrue0GetCurrentBid(), Brushes.Red);
                          
                   
    Draw.VerticalLine(this"Vline" CurrentBar0Brushes.PeachPuff);
                
    RC.SellAsk_rc(orderSize,GetCurrentAsk(),"G2Dn");
                    
    //EnterShort(0,orderSize,"G2Dn");
                 

    the strategy runs correctly if uncomment the original Entry orders.

    #2
    Why does RemoteControl inherit from Strategy?

    Is the RemoteControl class a strategy?

    No, it's not.

    It's just a plain old ordinary helper class.

    When defining RemoteControl, it should be redesigned with a constructor to accept the 'this' object, so that it can call methods from the Strategy object it is being used by.

    Check out the first post from this thread. Download the OP's attached code file and study his helper class called ExitManager. You need to borrow the idea behind this technique and do the same for your RemoteControl class.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Gerik, Today, 09:40 AM
    2 responses
    6 views
    0 likes
    Last Post Gerik
    by Gerik
     
    Started by RookieTrader, Today, 09:37 AM
    2 responses
    10 views
    0 likes
    Last Post RookieTrader  
    Started by alifarahani, Today, 09:40 AM
    1 response
    7 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by KennyK, 05-29-2017, 02:02 AM
    3 responses
    1,285 views
    0 likes
    Last Post NinjaTrader_Clayton  
    Started by AttiM, 02-14-2024, 05:20 PM
    11 responses
    186 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Working...
    X