NexusFi: Find Your Edge


Home Menu

 





Please help with simple strategy with SMA


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one lurker with 8 posts (1 thanks)
    2. looks_two forrestang with 7 posts (3 thanks)
    3. looks_3 shodson with 1 posts (0 thanks)
    4. looks_4 dimkrinichnyi with 1 posts (0 thanks)
    1. trending_up 5,261 views
    2. thumb_up 4 thanks given
    3. group 4 followers
    1. forum 17 posts
    2. attach_file 3 attachments




 
Search this Thread

Please help with simple strategy with SMA

  #1 (permalink)
dimkrinichnyi
Moscow
 
Posts: 2 since Jan 2011
Thanks Given: 2
Thanks Received: 0

Dear All.

Please help me.

I want to use very simple strategy - to open long when SMA cross Price in up direction and short when go to down.

I use such a code
if (CrossAbove(Close[0], SMA(Slow), 1) && Close[0]>Open[0])
EnterLong();

But this strategy not working every time when Close Price cross SMA.

What I did wrong?

Thank you

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Deepmoney LLM
Elite Quantitative GenAI/LLM
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
Better Renko Gaps
The Elite Circle
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
61 thanks
Funded Trader platforms
39 thanks
NexusFi site changelog and issues/problem reporting
26 thanks
Battlestations: Show us your trading desks!
26 thanks
The Program
18 thanks
  #3 (permalink)
lurker
New Delhi, India
 
Posts: 14 since Aug 2010
Thanks Given: 5
Thanks Received: 6


I hope the OP found the solution via strategy wizard.

I'm facing a simple but tough question so would like to use this thread before losing my sanity.

When I use both the SetStopLoss and ExitLong in the OnBarUpdate section, the strategy gives weird results. I have used the wizard to code a simple strategy of MA crossover, now trying to add a stoploss via

if (Position.MarketPosition == MarketPosition.Long)
{
SetStopLoss(CalculationMode.Price, Low[BarsSinceEntry("BUY")+2] - 50* TickSize);
}

IT gives weird results... like same entry and same exit price...............

Please HELP!

Reply With Quote
  #4 (permalink)
 
forrestang's Avatar
 forrestang 
Chicago IL
 
Experience: None
Platform: Ninja, MT4, Matlab
Broker: CQG, AMP, MB, DTN
Trading: E/U, G/U
Posts: 1,329 since Jun 2010
Thanks Given: 354
Thanks Received: 1,047


lurker View Post
I hope the OP found the solution via strategy wizard.

I'm facing a simple but tough question so would like to use this thread before losing my sanity.


IT gives weird results... like same entry and same exit price...............

Please HELP!

Try this. AFTER you tell your strategy to get long, insert this. Where the highlighted variables are your stopSize and profitTarget respectively:

 
Code
			if (Position.MarketPosition == MarketPosition.Long)
			{
					SetStopLoss("Long1", CalculationMode.Price, Position.AvgPrice - (initialStop*TickSize), false);
					SetProfitTarget("Long1", CalculationMode.Ticks, profitTarget);
			}

Reply With Quote
  #5 (permalink)
 
forrestang's Avatar
 forrestang 
Chicago IL
 
Experience: None
Platform: Ninja, MT4, Matlab
Broker: CQG, AMP, MB, DTN
Trading: E/U, G/U
Posts: 1,329 since Jun 2010
Thanks Given: 354
Thanks Received: 1,047


dimkrinichnyi View Post
Dear All.

Please help me.

I want to use very simple strategy - to open long when SMA cross Price in up direction and short when go to down.

For the OP if you're still around, when you use the CrossAbove() Function, you don't need to pass it the index like you are doing.

CrossAbove(), you used the highlighted in red, which is not needed:
 
Code
if (CrossAbove(Close[0], SMA(Slow), 1) && Close[0]>Open[0])
EnterLong();
When you pass it the close, you should do it like so:
 
Code
if (CrossAbove(Close, SMA(Slow), 1) && Close[0]>Open[0])
EnterLong();

Reply With Quote
  #6 (permalink)
 
shodson's Avatar
 shodson 
OC, California, USA
Quantoholic
 
Experience: Advanced
Platform: IB/TWS, NinjaTrader, ToS
Broker: IB, ToS, Kinetick
Trading: stocks, options, futures, VIX
Posts: 1,976 since Jun 2009
Thanks Given: 533
Thanks Received: 3,709


lurker View Post
I hope the OP found the solution via strategy wizard.

I'm facing a simple but tough question so would like to use this thread before losing my sanity.

When I use both the SetStopLoss and ExitLong in the OnBarUpdate section, the strategy gives weird results. I have used the wizard to code a simple strategy of MA crossover, now trying to add a stoploss via

if (Position.MarketPosition == MarketPosition.Long)
{
SetStopLoss(CalculationMode.Price, Low[BarsSinceEntry("BUY")+2] - 50* TickSize);
}

IT gives weird results... like same entry and same exit price...............

Please HELP!

You haven't provided enough details, there are a lot of things that could be causing your problems. I recommend you upload your strategy for further review.

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #7 (permalink)
lurker
New Delhi, India
 
Posts: 14 since Aug 2010
Thanks Given: 5
Thanks Received: 6


shodson View Post
You haven't provided enough details, there are a lot of things that could be causing your problems. I recommend you upload your strategy for further review.

Thanks, here is the code:

 
Code
if (CrossAbove(SMA(MAfast), SMA(MAslow), 1)
                && RSI(15, 1)[0] > 40)
            {
                EnterLong(DefaultQuantity, "Bought");
            }

 if (CrossBelow(SMA(MAfast), SMA(MAslow), 1))
            {
                ExitLong("", "Bought");
            }

            if (Position.MarketPosition == MarketPosition.Long)
            {
                SetStopLoss(CalculationMode.Price, Low[BarsSinceEntry("Bought")+1] + 0.50);
                DrawDot("stoptag1" + CurrentBar, true, 0, Low[BarsSinceEntry("Bought")+1] + 0.50, Color.BlueViolet);
            }
            
            
            
            if (CrossBelow(SMA(MAfast), SMA(MAslow), 1)
                && RSI(15, 1)[0] < 60)
            {
                EnterShort(DefaultQuantity, "Short");
            }
           
            if (Position.MarketPosition == MarketPosition.Short)            
            {
                SetStopLoss(CalculationMode.Price, High[BarsSinceEntry("Short") + 1] + 0.50);
                DrawDot("stoptag2" + CurrentBar, true, 0, High[BarsSinceEntry("Short") + 1] +0.50, Color.BlueViolet);
            }             

            
            if (CrossAbove(SMA(MAfast), SMA(MAslow), 1))
            {
                ExitShort("", "Short");
            }

Reply With Quote
  #8 (permalink)
lurker
New Delhi, India
 
Posts: 14 since Aug 2010
Thanks Given: 5
Thanks Received: 6


forrestang View Post
Try this. AFTER you tell your strategy to get long, insert this. Where the highlighted variables are your stopSize and profitTarget respectively:

 
Code
            if (Position.MarketPosition == MarketPosition.Long)
            {
                    SetStopLoss("Long1", CalculationMode.Price, Position.AvgPrice - (initialStop*TickSize), false);
                    SetProfitTarget("Long1", CalculationMode.Ticks, profitTarget);
            }

I'll probably need more help with the code

Reply With Quote
  #9 (permalink)
 
forrestang's Avatar
 forrestang 
Chicago IL
 
Experience: None
Platform: Ninja, MT4, Matlab
Broker: CQG, AMP, MB, DTN
Trading: E/U, G/U
Posts: 1,329 since Jun 2010
Thanks Given: 354
Thanks Received: 1,047


lurker View Post
I'll probably need more help with the code

Also, just something else, when you reset your stoploss when you are in the trade, you are globally changing it. So at the beginning, you might want to check to see if you are flat.... I.e. if you are flat you will want to re-initialize your stop to the original value.

So at the beginning, of onBarUpdate(), you will want to add something like:
 
Code
            if (Position.MarketPosition == MarketPosition.Flat)
            {
                    SetStopLoss("Long1", CalculationMode.Price, Position.AvgPrice - (initialStop*TickSize), false);
             }
Post the .cs file if you could.

Reply With Quote
  #10 (permalink)
lurker
New Delhi, India
 
Posts: 14 since Aug 2010
Thanks Given: 5
Thanks Received: 6



forrestang View Post
Post the .cs file if you could.

Guess I should have done this earlier... anyways help me out people

The logic is extremely simple... enter with a initial stop loss of previous bar's low; exit when either the stoploss is hit or MA crossover indicates sell.

Attached Files
Elite Membership required to download: tutorial.cs
Reply With Quote




Last Updated on November 1, 2011


© 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