Dark Theme
Light Theme
Trading Articles
Article Categories
Article Tools
Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to
register in order to view the content of the threads and start contributing to our community.
It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Please help with simple strategy with SMA
Updated November 1, 2011
Top Posters
looks_one
lurker
with 8 posts (1 thanks)
looks_two
forrestang
with 7 posts (3 thanks)
looks_3
shodson
with 1 posts (0 thanks)
looks_4
dimkrinichnyi
with 1 posts (0 thanks)
trending_up
5,362 views
thumb_up
4 thanks given
group
4 followers
forum
17 posts
attach_file
3 attachments
Please help with simple strategy with SMA
March 15th, 2011, 10:13 AM
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
Can you help answer these questions from other members on NexusFi?
Best Threads (Most Thanked) in the last 7 days on NexusFi
October 29th, 2011, 06:42 AM
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!
October 29th, 2011, 07:12 AM
Chicago IL
Urban Samurai
Experience: None
Platform: Ninja, MT4, Matlab
Broker: CQG, AMP, MB, DTN
Trading: E/U, G/U
Posts: 1,337 since Jun 2010
Thanks Given: 354
Thanks Received: 1,049
lurker
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 );
}
October 29th, 2011, 07:19 AM
Chicago IL
Urban Samurai
Experience: None
Platform: Ninja, MT4, Matlab
Broker: CQG, AMP, MB, DTN
Trading: E/U, G/U
Posts: 1,337 since Jun 2010
Thanks Given: 354
Thanks Received: 1,049
dimkrinichnyi
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();
October 29th, 2011, 11:20 AM
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,710
lurker
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.
October 30th, 2011, 10:04 AM
New Delhi, India
Posts: 14 since Aug 2010
Thanks Given: 5
Thanks Received: 6
shodson
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");
}
October 30th, 2011, 12:14 PM
New Delhi, India
Posts: 14 since Aug 2010
Thanks Given: 5
Thanks Received: 6
forrestang
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
October 30th, 2011, 12:46 PM
Chicago IL
Urban Samurai
Experience: None
Platform: Ninja, MT4, Matlab
Broker: CQG, AMP, MB, DTN
Trading: E/U, G/U
Posts: 1,337 since Jun 2010
Thanks Given: 354
Thanks Received: 1,049
lurker
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.
October 30th, 2011, 01:06 PM
New Delhi, India
Posts: 14 since Aug 2010
Thanks Given: 5
Thanks Received: 6
forrestang
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
Last Updated on November 1, 2011