NexusFi: Find Your Edge


Home Menu

 





Working on automating The Holy Grail & Sharky's method


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one RBSailing with 5 posts (1 thanks)
    2. looks_two wolfsch with 4 posts (0 thanks)
    3. looks_3 BigDog with 3 posts (0 thanks)
    4. looks_4 MXASJ with 2 posts (0 thanks)
    1. trending_up 7,968 views
    2. thumb_up 1 thanks given
    3. group 4 followers
    1. forum 15 posts
    2. attach_file 0 attachments




 
Search this Thread

Working on automating The Holy Grail & Sharky's method

  #1 (permalink)
BigDog
Chicago
 
Posts: 60 since Jun 2009
Thanks Given: 0
Thanks Received: 17

If i have an indicator that only paints bars, is it possible to pull that code into a strategy such that I can generate buy/sell signals from it?

I'm trying to automate these two strategies since everyone seems to have good experience (figure why can't this be automated...) adding in some position sizing, unwinding positions faster as risk is built up, etc etc

Trying to start with ADXVMA_sharky indicator... right now it only paints the adx line red/blue/yellow from my understanding...

what I want to implement is when red... sell, when blue... buy, when yellow... do nothing...

(from there on will build on the other indicators)

 
Code
protected override void OnBarUpdate()
{
    if( CurrentBar < 2 )
    {
        PDM.Set( 0 );
        MDM.Set( 0 );
        PDI.Set( 0 );
        MDI.Set( 0 );
        Out.Set( 0 );
        Main.Set( 0 );
        Rising.Set( 0 );
        Falling.Set( 0 );
        Neutral.Set( 0 );
        return;
    }
    try
    {
        int i = 0;
        PDM.Set( 0 );
        MDM.Set( 0 );
        if(Close[i]>Close[i+1])
            PDM.Set( Close[i]-Close[i+1] );//This array is not displayed.
        else
            MDM.Set( Close[i+1]-Close[i] );//This array is not displayed.
        
        PDM.Set(((WeightDM-1)*PDM[i+1] + PDM[i])/WeightDM);//ema.
        MDM.Set(((WeightDM-1)*MDM[i+1] + MDM[i])/WeightDM);//ema.
        
        double TR=PDM[i]+MDM[i];
        
        if (TR>0)
        {
            PDI.Set(PDM[i]/TR);
            MDI.Set(MDM[i]/TR);
        }//Avoid division by zero. Minimum step size is one unnormalized price pip.
        else
        {
            PDI.Set(0);
            MDI.Set(0);
        }
        
        PDI.Set(((WeightDI-1)*PDI[i+1] + PDI[i])/WeightDI);//ema.
        MDI.Set(((WeightDI-1)*MDI[i+1] + MDI[i])/WeightDI);//ema.

        double DI_Diff=PDI[i]-MDI[i];  
        if (DI_Diff<0)
            DI_Diff= -DI_Diff;//Only positive momentum signals are used.
        double DI_Sum=PDI[i]+MDI[i];
        double DI_Factor=0;//Zero case, DI_Diff will also be zero when DI_Sum is zero.
        if (DI_Sum>0)
            Out.Set(DI_Diff/DI_Sum);//Factional, near zero when PDM==MDM (horizonal), near 1 for laddering.
        else
            Out.Set(0);

          Out.Set(((WeightDX-1)*Out[i+1] + Out[i])/WeightDX);
        
        if (Out[i]>Out[i+1])
        {
            HHV=Out[i];
            LLV=Out[i+1];
        }
        else
        {
            HHV=Out[i+1];
            LLV=Out[i];
        }

        for(int j=1;j<Math.Min(ADXPeriod,CurrentBar);j++)
        {
            if(Out[i+j+1]>HHV)HHV=Out[i+j+1];
            if(Out[i+j+1]<LLV)LLV=Out[i+j+1];
        }
        
        
        double diff = HHV - LLV;//Veriable reference scale, adapts to recent activity level, unnormalized.
        double VI=0;//Zero case. This fixes the output at its historical level. 
        if (diff>0)
            VI=(Out[i]-LLV)/diff;//Normalized, 0-1 scale.
        
        //   if (VI_0.VIsq_1.VIsqroot_2==1)VI*=VI;
        //   if (VI_0.VIsq_1.VIsqroot_2==2)VI=MathSqrt(VI);
        //   if (VI>VImax)VI=VImax;//Used by Bemac with VImax=0.4, still used in vma1 and affects 5min trend definition.
                                //All the ema weight settings, including Chande, affect 5 min trend definition.
        //   if (VI<=zeroVIbelow)VI=0;                    
                                
        main.Set(((ChandeEMA-VI)*main[i+1]+VI*Close[i])/ChandeEMA);//Chande VMA formula with ema built in.
        if (main[0] > main[1])
        { Rising.Set(main[0]); Rising.Set(1, main[1]); }
        else if (main[0] < main[1])
        { Falling.Set(main[0]); Falling.Set(1, main[1]); }
        else
        { Neutral.Set(main[0]); Neutral.Set(1, main[1]); }
    }
    catch( Exception ex )
    {
        Print( ex.ToString() );
    }
}
i've bold faced and underlined the area I believe would set the conditions....

any ideas on how this could be done?

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
MC PL editor upgrade
MultiCharts
NexusFi Journal Challenge - May 2024
Feedback and Announcements
Exit Strategy
NinjaTrader
How to apply profiles
Traders Hideout
Trade idea based off three indicators.
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
41 thanks
Just another trading journal: PA, Wyckoff & Trends
30 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
23 thanks
GFIs1 1 DAX trade per day journal
21 thanks
  #2 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 800

Consider trying some logic like this:

if adxvma rising = true for a certain number of bars // do something long
if adxvma falling = true for a certain number of bars // do something short

Also look at price > adxvma for longs, opposite for shorts
Also look at adxvma main > signal for longs, opposite for shorts

Good luck!

Reply With Quote
  #3 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 800


if (Close[0] >= ADXVMA_sharky_paint(6, true).Main[0]
&& Close[
1] >= ADXVMA_sharky_paint(6, true).Main[1]
&& ADXVMA_sharky_paint(
6, true).Main[0] > ADXVMA_sharky_paint(6, true).Main[1]
&& ADXVMA_sharky_paint(
6, true).Main[1] > ADXVMA_sharky_paint(6, true).Main[2]

// more conditions and go LONG

Is part of the conditions for the LONG side of strat I've been testing recently. It looks for a two bar trend confirmation. Not the fastest, but worth considering.

Reply With Quote
  #4 (permalink)
BigDog
Chicago
 
Posts: 60 since Jun 2009
Thanks Given: 0
Thanks Received: 17

should have updated earlier... figured it out... i'm a doofus!

was very easy to implement just by simply calling the indicator into the strategy...


going to go through the thread again later tonite to see the specific conditions that = true in order to enter a trade for either strategy...


or if someone once to be a champion and post the exact conditions that'll make life much easier.... have much of the money management logic in place...

running a random entry for the money management nets positive edge, so that much does look good (was tested on 12000+ trades)

Reply With Quote
  #5 (permalink)
 YuvalW 
USA
 
Experience: Beginner
Platform: NinjaTrader
Posts: 26 since Jul 2009
Thanks Given: 4
Thanks Received: 17

Hi BigDog,

What money management do you use?

Thanks,

Yuval.

Reply With Quote
  #6 (permalink)
BigDog
Chicago
 
Posts: 60 since Jun 2009
Thanks Given: 0
Thanks Received: 17


YuvalW View Post
Hi BigDog,

What money management do you use?

Thanks,

Yuval.


scaling, selling or buying more agressively as building up risk, constantly working bids/asks etc

Reply With Quote
  #7 (permalink)
 
RBSailing's Avatar
 RBSailing 
Palm Beach Gardens
 
Experience: Intermediate
Platform: Ninja Trader
Posts: 21 since Jun 2009
Thanks Given: 5
Thanks Received: 6

I have been using the ADXVMA in a strategy too. I added a a MAslope data series to the indicator, made it a public data series. Then the strat just checks the value ( I used a -1 = negative, 0 = flat , 1 = positive slope) of the data series for the bar you are interested in.

When checking that actual "price" value of the plotted line of an indicator I use the simpler version ie non paint. I think it uses less system resources.

In a strategy that has multiple entry conditions I like to create variables in the strategy that I then set at the beginning of the OnBarUpdate based on the relevant indicator states at that bar. Then instead of calling the indicators over and over I just check the variables.

Follow me on Twitter Reply With Quote
  #8 (permalink)
 wolfsch 
waiblingen Germany
 
Experience: Intermediate
Platform: ninja, Meta 4
Broker: Mirus Zenfire
Trading: ES, forex
Posts: 49 since Jul 2009
Thanks Given: 7
Thanks Received: 3

Hi RBSailing , you mention a MASlope which I am looking for to work with the TripleEMA with 2 diiferent length, using the longer one as a filter. How can I get an indicator transformed to have the slope? I would like to have a general script to input in different indies. Have you an idea how to do?
Thanks Wolfsch

Reply With Quote
  #9 (permalink)
 
RJay's Avatar
 RJay 
Hartford, CT. USA
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG, Kinetick
Trading: RTY
Posts: 683 since Jun 2009
Thanks Given: 758
Thanks Received: 787


BigDog View Post
If i have an indicator that only paints bars, is it possible to pull that code into a strategy such that I can generate buy/sell signals from it?

I'm trying to automate these two strategies since everyone seems to have good experience (figure why can't this be automated...) adding in some position sizing, unwinding positions faster as risk is built up, etc etc

Trying to start with ADXVMA_sharky indicator... right now it only paints the adx line red/blue/yellow from my understanding...

what I want to implement is when red... sell, when blue... buy, when yellow... do nothing...

(from there on will build on the other indicators)

 
Code
protected override void OnBarUpdate()
{
    if( CurrentBar < 2 )
    {
        PDM.Set( 0 );
        MDM.Set( 0 );
        PDI.Set( 0 );
        MDI.Set( 0 );
        Out.Set( 0 );
        Main.Set( 0 );
        Rising.Set( 0 );
        Falling.Set( 0 );
        Neutral.Set( 0 );
        return;
    }
    try
    {
        int i = 0;
        PDM.Set( 0 );
        MDM.Set( 0 );
        if(Close[i]>Close[i+1])
            PDM.Set( Close[i]-Close[i+1] );//This array is not displayed.
        else
            MDM.Set( Close[i+1]-Close[i] );//This array is not displayed.
        
        PDM.Set(((WeightDM-1)*PDM[i+1] + PDM[i])/WeightDM);//ema.
        MDM.Set(((WeightDM-1)*MDM[i+1] + MDM[i])/WeightDM);//ema.
        
        double TR=PDM[i]+MDM[i];
        
        if (TR>0)
        {
            PDI.Set(PDM[i]/TR);
            MDI.Set(MDM[i]/TR);
        }//Avoid division by zero. Minimum step size is one unnormalized price pip.
        else
        {
            PDI.Set(0);
            MDI.Set(0);
        }
        
        PDI.Set(((WeightDI-1)*PDI[i+1] + PDI[i])/WeightDI);//ema.
        MDI.Set(((WeightDI-1)*MDI[i+1] + MDI[i])/WeightDI);//ema.

        double DI_Diff=PDI[i]-MDI[i];  
        if (DI_Diff<0)
            DI_Diff= -DI_Diff;//Only positive momentum signals are used.
        double DI_Sum=PDI[i]+MDI[i];
        double DI_Factor=0;//Zero case, DI_Diff will also be zero when DI_Sum is zero.
        if (DI_Sum>0)
            Out.Set(DI_Diff/DI_Sum);//Factional, near zero when PDM==MDM (horizonal), near 1 for laddering.
        else
            Out.Set(0);

          Out.Set(((WeightDX-1)*Out[i+1] + Out[i])/WeightDX);
        
        if (Out[i]>Out[i+1])
        {
            HHV=Out[i];
            LLV=Out[i+1];
        }
        else
        {
            HHV=Out[i+1];
            LLV=Out[i];
        }

        for(int j=1;j<Math.Min(ADXPeriod,CurrentBar);j++)
        {
            if(Out[i+j+1]>HHV)HHV=Out[i+j+1];
            if(Out[i+j+1]<LLV)LLV=Out[i+j+1];
        }
        
        
        double diff = HHV - LLV;//Veriable reference scale, adapts to recent activity level, unnormalized.
        double VI=0;//Zero case. This fixes the output at its historical level. 
        if (diff>0)
            VI=(Out[i]-LLV)/diff;//Normalized, 0-1 scale.
        
        //   if (VI_0.VIsq_1.VIsqroot_2==1)VI*=VI;
        //   if (VI_0.VIsq_1.VIsqroot_2==2)VI=MathSqrt(VI);
        //   if (VI>VImax)VI=VImax;//Used by Bemac with VImax=0.4, still used in vma1 and affects 5min trend definition.
                                //All the ema weight settings, including Chande, affect 5 min trend definition.
        //   if (VI<=zeroVIbelow)VI=0;                    
                                
        main.Set(((ChandeEMA-VI)*main[i+1]+VI*Close[i])/ChandeEMA);//Chande VMA formula with ema built in.
        if (main[0] > main[1])
        { Rising.Set(main[0]); Rising.Set(1, main[1]); }
        else if (main[0] < main[1])
        { Falling.Set(main[0]); Falling.Set(1, main[1]); }
        else
        { Neutral.Set(main[0]); Neutral.Set(1, main[1]); }
    }
    catch( Exception ex )
    {
        Print( ex.ToString() );
    }
}
i've bold faced and underlined the area I believe would set the conditions....

any ideas on how this could be done?

Hey BigDog,

I think this strategy is possible. Just one huge problem!!!

This indicator code you are using is repainting the last bar!!!

Check all code lines and do the following.

if the code line updates for both current bar and previous bar like this...

{ Rising.Set(main[0]); Rising.Set(1, main[1]); }

Simply comment out the update to the previous bar like this...

{ Rising.Set(main[0]); // Rising.Set(1, main[1]); }

As far as the strategy goes, when you select this indicator, select indicator output field.

Select each output for each condition. if condition => 1 ( Buy, sell, or do nothing.)

Let me know how it goes,

RJay

Reply With Quote
  #10 (permalink)
 
RBSailing's Avatar
 RBSailing 
Palm Beach Gardens
 
Experience: Intermediate
Platform: Ninja Trader
Posts: 21 since Jun 2009
Thanks Given: 5
Thanks Received: 6



wolfsch View Post
Hi RBSailing , you mention a MASlope which I am looking for to work with the TripleEMA with 2 diiferent length, using the longer one as a filter. How can I get an indicator transformed to have the slope? I would like to have a general script to input in different indies. Have you an idea how to do?
Thanks Wolfsch

There is an indicator in the download section
ColorSampleUniversalMovingAverage
That should do the job for you. I am not sure the exact algorithm they use. I will look at it and posagain. I modified the slope angle calculation that I think originate at NT forum. That calculation averaged the indicator value of the last 2 bars and then compared it to the current value. I removed the averaging so I just check the slope form the last bar to the current bar.
Have you lookad at the LinReg Ma?

Follow me on Twitter Reply With Quote




Last Updated on January 21, 2010


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts