| / | Forum |
|
evilmonkey42
2008.11.03 21:33
Been trying to get an EA to work right for 2 weeks now. nothing i try works. if i get the close to work, it wont open, if i get the open to work, it wont close. every code bit that i try to get it to work on a new bar only either does not work or runs multiple times.... This code is no where near what I started with. Everytime it would not work, I removed something to make it simpler to try and find my error. If there is anyone who can throw me a bone and help me get this to work...Thank you |
|
Interview with Alexander Egorov (Aver) While writing expert advisors, I knew from practice that trailing stop rarely pays off, one just loses one's profits. Though, it can be related to my experts, not to the real trading. I tried to use trailing stops instead of strictly set profit. It did not pay off. |
|
phy
2008.11.03 22:30
Problem #1: if(TimeCurrent() == Time[0]) Improvement: static int oldBarTime; if(oldBarTime != Time[0]){ oldBarTime = Time[0]; ... continue with your code . . Problem #2 for (cnt=total;cnt>0;cnt--) Improvement: for(cnt = OrdersTotal()-1; cnt >= 0; cnt--) . . Problem #3 if(OrderType() <= OP_SELL==true || OrderType() <= OP_BUY==true) Improvement: if(OrderType() == OP_SELL || OrderType() == OP_BUY) . . Problem #4 You can't close both buy and sell orders using Ask for the price. OrderClose(OrderTicket(),OrderLots(),Ask,5,CLR_NONE); //Close Orders . . Problem #5 NormalizeDouble(LStopLose,4); Improvment: lStopLose = NormalizeDouble(LStopLose,4); . . Problem #6 You are using return(0) haphazardly. return(0) inside start() causes your progam to immediately exit (until the next tick restarts the code) You probably want to remove all of them inside start() except at the very end. . . Problem #7 cnt=0; Why are you forcibly resetting the loop counter? . . Overall Logic: If a new bar is detected, close all existing positions. Open a new Buy position if CCI is rising. Open a new Sell position if CCI is falling. . . There may be more problems not yet visible. . Please use the SRC button here in this editor to format your code |
|
phy
2008.11.03 22:31
Been trying to get an EA to work right for 2 weeks now. nothing i try works. if i get the close to work, it wont open, if i get the open to work, it wont close. every code bit that i try to get it to work on a new bar only either does not work or runs multiple times.... Well, that occurs because you haven't learned how to write code yet. Write a little piece at a time, and TEST IT to see if it works, and see if it works as you think it should work, then write a little more and TEST IT AGAIN. Don't try to write the whole program at one time. Example, you are trying to detect a new bar, and are failing. Write only that, and get it to work, before you move on. It will save a lot of frustration. |
|
evilmonkey42
2008.11.04 08:37
Thanks for the help, the alert bit was infinitely useful It was the returns i think that were killing it and seperating the closing out section. Everything seems to be working except this bit: Problem #1: if(TimeCurrent() == Time[0]) Improvement: static int oldBarTime; if(oldBarTime != Time[0]){ oldBarTime = Time[0]; ... continue with your code i put in an alert with it so I know it is running it, but it is running the whole EA every few seconds, but it seems to be random, not lining up with ticks or any pattern that i can see. |
|
phy
2008.11.04 18:44
The start() function of an EA is called on every tick of the chart to which it is attached static int oldBarTime; if(oldBarTime != Time[0]){ oldBarTime = Time[0]; ... continue with your code here } Check the brackets {} in what you wrote. |
|
evilmonkey42
2008.11.04 18:54
so i've been messing around with the new bar detecter thing, found this... when i change this: static int oldBarTime; if(oldBarTime != Time[0]){ Alert("new bar"); oldBarTime = Time[0]; ... continue with your code to static int oldBarTime; oldBarTime = Time[0]; //new bit if(oldBarTime != Time[0]){ Alert("new bar"); oldBarTime = Time[0]; ... continue with your code the EA will still run. I know it is looking at it as it prints the new bar alert, but it seems to be completely ignoreing the oldBarTime rule. |
|
evilmonkey42
2008.11.04 19:04
I've got something that has some potential: int vol; vol = 1; if (iVolume(NULL,0,0) == vol ) { Alert("new bar"); vol = 0; ...continue this should start the EA on the first tick of a new bar, then stop it due to changin of vol... |
|
phy
2008.11.04 19:15
Ok, have fun experimenting. Have a nice day. |
|
TXAggie00
2008.11.04 23:18
evilmonkey42 wrote >>
I've got something that has some potential: int vol; vol = 1; if (iVolume(NULL,0,0) == vol ) { Alert("new bar"); vol = 0; ...continue this should start the EA on the first tick of a new bar, then stop it due to changin of vol... phy already gave you the answer that virtually everyone uses when they only want to run logic at the formation of a new bar. Trust him, it works. If it isn't working for you, then you messed up somewhere. datetime currTime; datetime prevTime; int start() { currTime=Time[0]; if(currTime!=prevTime) { prevTime = currTime; // ALL OF YOUR LOGIC GOES HERE!!!!!!!!!!!! } return(0); } |