Forex Factory (https://www.forexfactory.com/forum.php)
-   Platform Tech (https://www.forexfactory.com/forumdisplay.php?f=69)
-   -   Programming of SMA and SMA cross over (https://www.forexfactory.com/showthread.php?t=214806)

KPForex Jan 8, 2010 5:19am | Post# 1

Programming of SMA and SMA cross over
 
Hi, i am using this website to build my own simple ea
http://sufx.core.t3-ism.net/ExpertAd...ndex.html#Buy1

But how do i code for to go for a sell Entry when SMA(26) cross over SMA(8) and buy entry when SMA(8) cross over SMA(26)?

I not sure what is the alogorithm for crossing over for MA? is it >= or other stuff? please help.. thanks

luxinterior Jan 8, 2010 5:23am | Post# 2

Check the link in my sig. It will walk you through how to create an MA crossover and you can see the logic. You don't need any prior programming experience to follow it.

Hope that helps.

Lux

KPForex Jan 9, 2010 4:18am | Post# 3

yo, can anyone help? thanks

LittleLuca Jan 9, 2010 7:36am | Post# 4

Its the >= "stuff". http://www.hermit.cc/teach/HO/dbms/OPTABLE.HTM

This link should give you a basic over view of the comparison of different values!

But yes you wish to use SMA(28) >= SMA(8) (which means when the value of sma28 is greater than (or equal to) sma8 then sell!)

HTH

KPForex Jan 9, 2010 11:27am | Post# 5

I seee... thanks...

So for SMA(28) cross over SMA(8), that means is equivalent to SMA(28) >= SMA (8)?

thanks


Its the >= "stuff". http://www.hermit.cc/teach/HO/dbms/OPTABLE.HTM

This link should give you a basic over view of the comparison of different values!

But yes you wish to use SMA(28) >= SMA(8) (which means when the value of sma28 is greater than (or equal to) sma8 then sell!)

HTH

hayseed Jan 9, 2010 11:43am | Post# 6

crossings
 
hey kp...... crossings usually require 2 conditions..... SMA(28) >= SMA (8) one part..... such as below........h




Inserted Code
 
     double fast        = iMA(NULL, 0, fastmaperiods, 0,  fastmethod, fastprice, 1);
     double fast2       = iMA(NULL, 0, fastmaperiods, 0,  fastmethod, fastprice, 2);   
     double slow        = iMA(NULL, 0, slowmaperiods, 0,  slowmethod, slowprice, 1); 
     double slow2       = iMA(NULL, 0, slowmaperiods, 0,  slowmethod, slowprice, 2);   
 
     if(fast > slow && fast2 <= slow2) {macrossbuy  = true;} else  {macrossbuy  = false;} 
     if(fast < slow && fast2 >= slow2) {macrosssell = true;} else  {macrosssell = false;}

KPForex Jan 10, 2010 6:26am | Post# 7

what if i am using the http://sufx.core.t3-ism.net/ExpertAd...ndex.html#Buy1

hey kp...... crossings usually require 2 conditions..... SMA(28) >= SMA (8) one part..... such as below........h




[code]...

hayseed Jan 10, 2010 8:10am | Post# 8

zero code
 
hey kp..... it's admirable of you to attempt the ea on your own....


there are several versions of those 'zero code' programs.... sufx core is one...... all have the same basic design, change the shift variable to help create the two conditions..... as example, the before condition would have a shift value of 2, and the after condition would have a shifit value of 1.......

//----

those type 'zero code' programs were/are abused to the point that i just about can't even look at the code they produce..... so, due to that personal flaw, my expierence with them is limited......h

KPForex Jan 11, 2010 1:28am | Post# 9

ok thanks. is it possible to help me with this simple EA? thanks

hey kp..... it's admirable of you to attempt the ea on your own....


there are several versions of those 'zero code' programs.... sufx core is one...... all have the same basic design, change the shift variable to help create the two conditions..... as example, the before condition would have a shift value of 2, and the after condition would have a shifit value of 1.......

//----

those type 'zero code' programs were/are abused to the point that i just about can't even look at the code they produce..... so, due to that...

hayseed Jan 11, 2010 11:00am | Post# 10

ea
 
hey kp..... sure, we can give it a shot..... just post your buy/sell rules and such..... give them plenty of thought and try to be as explict as possible....h

KPForex Jan 11, 2010 11:22am | Post# 11

ok, here we goes:::

Indicator: EMA8(blue), SMA26(red), CCI55(with zero as centre readin), CCI34(with zero as centre reading) and RSI26 (with 48 as centre reading)


BUY Entry

1) When EMA crosses SMA to the upside, CCI55 and CCI34 crosses the zero reading and RSI26 crosses the 48 reading

SELL Entry

1)the reverse of buy

Note:
1) never take a trade if one of the indicators is doing otherwise of the other indicators

2) if all the requirement is meant for the trade, the next thing to watch for is the deviation of the PA from the MA crosses

3) never take a trade with opposing candle ( i mean dont go long with a closed bear canndle and vice versa)

4) before taking a trade wait for the current candle to close meaning only take a trade at the opening of another candle

5) if the deviation of the PA from the MA is wide wait for the price consolidation towards the MA and obey rule 3&4 before taking a trade

Money Management:
SL: 30 pips (can adjust)
TP: 20 pips (can adjust)

hey kp..... sure, we can give it a shot..... just post your buy/sell rules and such..... give them plenty of thought and try to be as explict as possible....h

hayseed Jan 11, 2010 2:23pm | Post# 12

momentum
 
hey kp..... i'll be in my prefered office shortly, a deer stand..... will code it up there.....

but can tell without a doubt it will not work as you hope..... your using 2 momentum indicators with 3 different period settings in conjunction with 2 moving averages....

the odds of all 5 needed conditions to happen on the same bar are just about 0.... you might get a few signals a year....

then when you throw the bullish/bearish candle into the mix, well, it's just far to restricitive to place trades.....

place all those indicators on a chart and scroll back..... likely you'll give up before 3 trades are found.....


momentum indicators like, rsi, cci, wpr, stoch, are thought by some as leading indicators.... with leading indicators, many will just require that the indicator be above or below a value rather than crossing a value, when used in a ma cross system....

so instead of,

CCI55 and CCI34 crosses the zero reading and RSI26 crosses the 48 reading

they would use,

CCI55 and CCI34 > zero and RSI26 > 48 , for a buy..... along with the ma cross.....


//----

of course if it's just a pure momentum system, then rsi/cci/wpr/stoch crossing a value is widely used.....


//----

you've been mentioning sma's so far, but in the rules you say,

Indicator: EMA8(blue), SMA26(red),

did you mean sma8(blue) .......h

KPForex Jan 12, 2010 12:11am | Post# 13

Oh i see.. but u put it in a H1 TF, it will match sometimes.. maybe once a day. Maybe u can help me to program it and we will test together...

anyway it is EMA(8) and SMA(26)....

hey kp..... i'll be in my prefered office shortly, a deer stand..... will code it up there.....

but can tell without a doubt it will not work as you hope..... your using 2 momentum indicators with 3 different period settings in conjunction with 2 moving averages....

the odds of all 5 needed conditions to happen on the same bar are just about 0.... you might get a few signals a year....

then when you throw the bullish/bearish candle into the mix, well, it's just far to restricitive to place trades.....

place all those indicators on a chart...

hayseed Jan 12, 2010 7:54am | Post# 14

crossover
 
1 Attachment(s)
hey kp...... here ya go..... all values are your default settings except for the one you have not mentioned, the distance from the ma...... pips sets that value..... if the price is less than the ma +/- that value it will trade.... if not, it will wait..... the larger the timeframe, the larger that setting should be.....

your tying it's hands and feet pretty tight with so many strict conditions...... so don't expect a whole lot of action.....h
KPForex.mq4

KPForex Jan 12, 2010 8:48am | Post# 15

hey kp...... here ya go..... all values are your default settings except for the one you have not mentioned, the distance from the ma...... pips sets that value..... if the price is less than the ma +/- that value it will trade.... if not, it will wait..... the larger the timeframe, the larger that setting should be.....

your tying it's hands and feet pretty tight with so many strict conditions...... so don't expect a whole lot of action.....h

really appreciate ur prompt action man... will test it out tomorrow in my office. By the way, have u done any testing so far on all pairs? hehe

hayseed Jan 12, 2010 9:42am | Post# 16

testing
 
hey kp..... i ran it on all timeframes on just a couple pairs, more for code check than anything else..... trades less than once a month , as expected.......

i'm back in the deer stand now..... things are slow so i'll add the ability to switch to a less restrictive and more conventional way of thinking.....

unless that trophy 3 point steps out......h

KPForex Jan 12, 2010 9:49am | Post# 17

thanks man...maybe u can put in ur ideas on how we can improve this EA?

hey kp..... i ran it on all timeframes on just a couple pairs, more for code check than anything else..... trades less than once a month , as expected.......

i'm back in the deer stand now..... things are slow so i'll add the ability to switch to a less restrictive and more conventional way of thinking.....

unless that trophy 3 point steps out......h

KPForex Jan 12, 2010 9:41pm | Post# 18

Hi Hayseed,

I thought of one simple strategy.. but need ur help to change the EA... it works on one pair. GBPUSD for 1H TF. The criteria is as below... pretty simple.

Buy Signal
Criteria - SMA(5)and SMA(10) is above SMA(62)

Sell Signal
Criteria - SMA(5)and SMA(10) is below SMA(62)

For money management wise, is as follows:

the EA would open and close trade on time 00:00hrs daily.

For example, it will open a new trade at 00:00 hrs (13 Jan), if SMA(5)and SMA(10) is above SMA(62), it will just trigger a long signal. Then the next day at 00:00hrs(14 Jan), it will close the trade regardless of whether loss or profit. Then it will again look for the criteria, if it is SMA(5)and SMA(10) is below SMA(62), then will do a short signal.

I forsee that it will be beneficial. is it possible to come out a EA like this? thanks

tommbstone Jan 13, 2010 1:01am | Post# 19

hahah I can see him now up in the deer stand clicking away.. The sound of the clicking must lure them in.

KPForex Jan 13, 2010 1:25am | Post# 20

hahah I can see him now up in the deer stand clicking away.. The sound of the clicking must lure them in.
what does that means?


© Forex Factory