Coding for beginners - this is how Steve started

The forum for experienced coders to upload their helpful hints, tips and lessons.
garyfritz

Re: Coding for beginners - this is how Steve started

Post by garyfritz »

traderduke wrote:Thank for that explanation. The "second one runs all the start() code on every tick" seems to give the closest backtest results to forward testing.
No, because these "infinite loop" EAs generally process multiple pairs, and Empty4 cannot backtest them. They are for realtime forward testing/trading only.
jjasper7
Trader
Posts: 87
Joined: Mon Mar 19, 2012 11:44 pm
Location: Mesa,AZ (near Phoenix)

Re: Coding for beginners - this is how Steve started

Post by jjasper7 »

i am trying to modify some code in simpleshelley, but suspect i am having some array problems that i do not understand. i have inserted alerts (ss3 and ss4) that print proper values for TradePair[][4] as it is being saved, but the printout of alert(ss4) shows only the last movingaverage calculated is saved for ALL instances of TradePair[cc][4] somehow!! i do not understand, can someone please explain what is happening?

code:
string TradePair[][4]; //jj

void ReadTable()
{
//Fills the array table
int cc = 0;
double v = 0;
string symbol;

//jj set TradePair[cc][1] = buyhold; TradePair[cc][2] = buy
for (cc = 0; cc < NoOfPairs; cc++)
{
TradePair[cc][3]=" "; //jj
TradePair[cc][4]=" "; //jj
symbol = TradePair[cc][0];
Comment(Gap, "Reading the indicators: " + symbol);
//Trading time frame Slope

//jj
int xx,ltp;
int lt=Period();
int ltp=240;

double Slope = GetSlope(symbol,ltp, 0); //jj current slope !d1
TradePair[cc][3]=DoubleToStr(Slope,2); //jj
TradePair[cc][1] = nottradable;
if (Slope >= 0.4) TradePair[cc][1] = buyhold;
if (Slope <= -0.4) TradePair[cc][1] = sellhold;

// market direction
double wo = iMA(symbol,ltp,5,1,MODE_LWMA,PRICE_OPEN,0); //jj h4 !w1
double ma = iMA(symbol,lt,1,0,MODE_SMA,PRICE_MEDIAN,0); //jj current price
double oma = iMA(symbol,lt,3,0,MODE_SMA,PRICE_MEDIAN,1); //jj past price
TradePair[cc][2] = none;
TradePair[cc][4]=DoubleToStr(ma,5); //jj

Alert( "SS3 ",TradePair[cc][0]," ma",TradePair[cc][3]," a",TradePair[cc][4]," cc",cc); //jj
if (ma > wo && ma>oma) TradePair[cc][2] = buy; //jj add direction
if (ma < wo && ma<oma) TradePair[cc][2] = sell; //jj

}//for (cc = 0 ; cc < ArraySize(TradePair); cc++)

Alert("SS2 ",TradePair[0][0]," table calc, ma=", TradePair[0][4]," ", TradePair[1][4]," ", TradePair[2][4]); //jj
}//End void ReadTable()
jjasper7
Trader
Posts: 87
Joined: Mon Mar 19, 2012 11:44 pm
Location: Mesa,AZ (near Phoenix)

Re: Coding for beginners - this is how Steve started

Post by jjasper7 »

the tma slope calculation i get from simpleshelley and from 10.2 tma slope are very different. is there something wrong or is one of them just off in magnitude? i guess the basic question is do they cross zero at about the same time, and the +/- .8 mark need adjustment in shelley?
User avatar
NeoTrader
Trader
Posts: 436
Joined: Wed Apr 04, 2012 2:52 pm
Location: small Village at Lake Chiemsee, Bavaria, Germany

Re: Coding for beginners - this is how Steve started

Post by NeoTrader »

hi jjasper,
jjasper7 wrote:the tma slope calculation i get from simpleshelley and from 10.2 tma slope are very different. is there something wrong or is one of them just off in magnitude? i guess the basic question is do they cross zero at about the same time, and the +/- .8 mark need adjustment in shelley?
Just did a quick peek in simple shelley v1b code and the tma code is the standard (repainting) TMA Code. It should be the same value as you see on the standard TMAslope. Have you changed any settings in your slope or are you using a version with TMATrue calculations?

happy trading,

NeoTrader

-
User avatar
fxozgirl
Trader
Posts: 1176
Joined: Wed Nov 16, 2011 9:16 am
Location: Melbourne, Australia

Re: Coding for beginners - this is how Steve started

Post by fxozgirl »

SteveHopwood wrote:Hey guys.

I see a number of people here wanting to get more involved with coding. This sounds like An Excellent Plan to me.

Attached is the stuff I used to get started. The contents of the zip are freely available on the net, so I am sure CodersGuru will not mind.

This entire forum, and every piece of software I have ever coded for Forex trading has its origins in info provided by the lessons in the zipfile.

My/our warmest appreciation to CodersGuru.

Have fun guys. I do.

:D
Ok, I've decided to dip a toe in the water here and start to learn some coding. Time is my biggest enemy, so will most likely be slow going.

Thanks Steve for sharing how you started :D
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Re: Coding for beginners - this is how Steve started

Post by SteveHopwood »

fxozgirl wrote:
SteveHopwood wrote:Hey guys.

I see a number of people here wanting to get more involved with coding. This sounds like An Excellent Plan to me.

Attached is the stuff I used to get started. The contents of the zip are freely available on the net, so I am sure CodersGuru will not mind.

This entire forum, and every piece of software I have ever coded for Forex trading has its origins in info provided by the lessons in the zipfile.

My/our warmest appreciation to CodersGuru.

Have fun guys. I do.

:D
Ok, I've decided to dip a toe in the water here and start to learn some coding. Time is my biggest enemy, so will most likely be slow going.

Thanks Steve for sharing how you started :D
Go for it, Tiger.

:D
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
jjasper7
Trader
Posts: 87
Joined: Mon Mar 19, 2012 11:44 pm
Location: Mesa,AZ (near Phoenix)

Re: Coding for beginners - this is how Steve started

Post by jjasper7 »

thanks neo, so i guess that means i am using the wrong tma indi. which is the proper one?
also, do you have any ideas that might account for my TradePair[x][4] printout not containing the expected calculated values after exiting the loop?
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Re: Coding for beginners - this is how Steve started

Post by SteveHopwood »

jjasper7 wrote:thanks neo, so i guess that means i am using the wrong tma indi. which is the proper one?
also, do you have any ideas that might account for my TradePair[x][4] printout not containing the expected calculated values after exiting the loop?
Not sure if this helps with your issue, but you might like to go to any of my recent EA's that use Slope and pinch the GetSlope code from there. The code was provided by Baluda, who understands this stuff, and cuts out all the iCustom calls otherwise involved.

Sorry if I am barking at the wrong moon here.
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
jjasper7
Trader
Posts: 87
Joined: Mon Mar 19, 2012 11:44 pm
Location: Mesa,AZ (near Phoenix)

Re: Coding for beginners - this is how Steve started

Post by jjasper7 »

yea i think the tma code is in shelley and from baluda, and the tma indi i was comparing it against was not the most recent/corrected version. but there are so many instances floating around that i am unclear which is the best stand-alone version to use and that displays the correct recent value. also am assuming the values look alike except in magnitude so am using the one as in the ss code. the outstanding question, though, is still about the array in my code snippet. proper values are stored away and displayed by the ss3 alert, but after the looping is done, the ss2 alert shows that the values for the 4th element of the array was not saved as intended, and i do not see what i did wrong. that 4th element for each instance of the array, contains the same value as last calculated or at least does not contain the value that was calculated for it and gets/displays only the last calculated value.
User avatar
traderduke
Trader
Posts: 306
Joined: Mon Nov 28, 2011 7:30 pm
Location: East Coast USA

Re: Coding for beginners - this is how Steve started

Post by traderduke »

Gary
with the "run once per candle" removed from the Start(), I'm getting multiple entries in one candle, see the attached. This happens when the "trailing stop" or "take profit" is smaller then the RENKO block.

What is the code for limiting one trade per candle??

Thank you for all your help!


garyfritz wrote:
traderduke wrote:Thank for that explanation. The "second one runs all the start() code on every tick" seems to give the closest backtest results to forward testing.
No, because these "infinite loop" EAs generally process multiple pairs, and Empty4 cannot backtest them. They are for realtime forward testing/trading only.
You do not have the required permissions to view the files attached to this post.
Post Reply

Return to “Coding Lessons - info for all”