Hello i have a loop placed in the code (blue) instead of (if(OrdersTotal()<=10000000)).
This wil work fine for 1 order but when i change (if (OpenLongOrders ==0)) in (if (OpenLongOrders <=10))
it keeps on getting orders until 10.
but i would like only to buy if value decreased 0.10 point.
double pips;Play video | Please edit your post. For large amounts of code, attach it. |
double pips; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- double ticksize = MarketInfo(Symbol(),MODE_TICKSIZE); if(ticksize ==0.0001||ticksize ==0.001) pips = ticksize * 10; else pips = ticksize; //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- static double koop = 10000000; double a = iMA(NULL,1,5,0,0,0,1); double b = Close[0]; if (b>a) if (Close[0]<koop) if(OrderSelect(1968,SELECT_BY_TICKET,MODE_TRADES)==0) int total = OrdersTotal(); int i; double OpenLongOrders = 0; for( i=0;i<OrdersTotal();i++) { OrderSelect(i, SELECT_BY_POS ); if ( OrderSymbol() == Symbol() && OrderMagicNumber() == 1968) { int type = OrderType(); if (type == OP_BUY ) {OpenLongOrders=OpenLongOrders+1;} }} if (OpenLongOrders ==0) {OrderSend(Symbol(),OP_BUY,0.01,Ask,3,0,Ask+10*pips,NULL,1968,0,Green); if (Close[0] >= koop) return (false); koop=Close[0]-10*pips; return(true); } if(b<a) if (Close[0]>koop+20*pips) if(OrdersTotal()<=10000000) {OrderClose(1968,0.01,Ask,3,Blue); if (Close[0]<=koop) return (false); koop=Close[0]-10*pips; return(true); } if (OrdersTotal()==0) koop=10000000; return(true); //---- return(0); }
Thanks
Here is the first code
double pips; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- double ticksize = MarketInfo(Symbol(),MODE_TICKSIZE); if(ticksize ==0.0001||ticksize ==0.001) pips = ticksize * 10; else pips = ticksize; //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- static double koop = 10000000; double a = iMA(NULL,1,5,0,0,0,1); double b = Close[0]; if (b<a) if (Close[0]<koop) if(OrdersTotal()<=10000000) {OrderSend(Symbol(),OP_BUY,0.01,Ask,3,0,Ask+10*pips,NULL,1968,0,Green); if (Close[0] >= koop) return (false); koop=Close[0]-10*pips; return(true); } if(b<a) if (Close[0]>koop+20*pips) if(OrdersTotal()<=10000000) if( OrderClose(1968,0.01,Ask,3,Blue)); {if (Close[0]<=koop) return (false); koop=(Close[0])-10*pips; return(true);} if (OrdersTotal()==0) koop=10000000; return(true); //---- return(0); }
Thanks
Here is the first code
Buddy,
The code looks like a joke and it's not April's fools.
You need to read the documentation on ALL functions you used in your code and if you don't understand something come back and ask.
You will get explanations and help but you need to do your bit first.
There are examples in the help file and online documentation for how to use in a proper way all the functions you need.
int start() // note that this is an integer function and has to return an integer { //---- static double koop = 10000000; // what is this supposed to be ? double a = iMA(NULL,1,5,0,0,0,1); // do you understand the iMA function ? double b = Close[0]; // do you understand the Close[] function ? if (b<a) // this is the same as if (Close[0]<koop) // this if(OrdersTotal()<=10000000) // 10 million ? Are you serious ? {OrderSend(Symbol(),OP_BUY,0.01,Ask,3,0,Ask+10*pips,NULL,1968,0,Green); // if (Close[0] >= koop) // When is the close of a bar be over 10 million ? return (false); // int start() cannot return true or false ! koop=Close[0]-10*pips; // what is the value of pips ? It's zero, from the start return(true); // int start() cannot return true or false ! } // this is an amazing way of using if(b<a) if (Close[0]>koop+20*pips) if(OrdersTotal()<=10000000) if( OrderClose(1968,0.01,Ask,3,Blue)); {if (Close[0]<=koop) return (false); koop=(Close[0])-10*pips; return(true);} if (OrdersTotal()==0) koop=10000000; return(true); //---- return(0); }
Do some reading first and you'll be laughing at the code you submitted .
Cheers
Hello again
I have solved my problem. I have also put a trailer stop in it. And changed some little things
i have my code running on several charts.
I just had to change the magicnumber.
When you load the ea then set your spread to the spread of your symbol and chose an magicnumber.
Only buy the stock with a value between 15 and 35.
Your highest lost will be about 500 euro (when the company goes broke) and you wil make a profit of 1% a month.
Well it's not a great ea but it's working.
I am just new at trading and programming so i will welcom any comment.
double pips; extern static double koop = 30; extern double maxprice = 30; extern double magicnumber = 1903; extern double spread = 10; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- double ticksize = MarketInfo(Symbol(),MODE_TICKSIZE); if(ticksize ==0.0001||ticksize ==0.001) pips = ticksize * 10; else pips = ticksize; //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- AdjustTrail(); static double koop = 10000000; if(OrdersTotal()<=10000000) { double a = iMA(NULL,1,5,0,0,0,1); double b = Close[0]; if (b<a) if (Close[0]<koop) {OrderSend(Symbol(),OP_BUY,0.01,Ask,3,0,0,NULL,magicnumber,0,Green); if (Close[0] >= koop) return (false); koop=Close[0]-10*pips; return(true); }} else if(OrdersTotal()<=10000000) { if(b<a) if (Close[0]>koop+20*pips) {OrderClose(magicnumber,0.01,Ask,3,Blue); if (Close[0]<=koop) return (false); koop=Close[0]-10*pips; return(true); }} if (OrdersTotal()==0) koop=maxprice; return(true); //---- return(0); } //+------------------------------------------------------------------+ void AdjustTrail() { for(int b = OrdersTotal()-1;b >= 0;b--) { if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) if(OrderMagicNumber()==magicnumber) if (OrderSymbol()==Symbol()) if(OrderType()==OP_BUY) if(Bid-OrderOpenPrice()>(spread+20)*Point) if(OrderStopLoss()<Bid-Point*20) OrderModify(OrderTicket(),OrderOpenPrice(),Bid-(Point*20),OrderTakeProfit(),0,CLR_NONE); if( koop<OrderTakeProfit()) koop = Close[0]-10*Point; }}
double pips; extern static double buylevel = 30; // Close must be under buylevel before place a buy extern double maxprice = 30; // The price must be below maxprice extern double lowprice = 10; // The price must be above lowprice extern double magicnumber = 1903; // each chart must have a different magicnumber //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- double ticksize = MarketInfo(Symbol(),MODE_TICKSIZE); // By using pips the ea can be used on different brookers (3 or 5 digits) if(ticksize ==0.0001||ticksize ==0.001) pips = ticksize * 10; else pips = ticksize; //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- AdjustTrail(); // Check if the trailer stop can be used static double buylevel = 10000000; // Start with a random number to get 1 buy order if(OrdersTotal()<=10000000) // make sure you can always place a buy order { double a = iMA(NULL,1,5,0,0,0,1); // making use of the moving average double b = Close[0]; // b = Close if (b<a) // if close is smaller than moving average if (Close[0]<buylevel) // if close is smaller than buylevel if (Close[0]>lowprice) // if close is greater than the lowprice (this way you can stop buying at the lowprice) {OrderSend(Symbol(),OP_BUY,0.01,Ask,3,0,0,NULL,magicnumber,0,Green); // this will place the buyorder if (Close[0] >= buylevel) // if close is greater then buylevel return (false); // do nothing buylevel=Close[0]-10*pips; // and else buylevel is the price of close - 10 points return(true); // change buylevel in new price }} else if(OrdersTotal()<=10000000) // else start with a random number { if(b<a) // if close is smaller than moving average if (Close[0]>buylevel+20*pips) // if close is greater then buylevel + 20 points if (Close[0]>lowprice) // if close is greater than the lowprice (this way you can stop buying at the lowprice) {OrderClose(magicnumber,0.01,Ask,3,Blue); // if true then sell buyorder if (Close[0]<=buylevel) // if close smaller or equaal to buylevel return (false); // do nothing buylevel=Close[0]-10*pips; // else buylevel is the price of close - 10 points return(true); // change buylevel in new price }} if (OrdersTotal()==0) // if there are no orders open buylevel=maxprice; // then buylevel is maxprice return(true); // change buylevel in maxprice //---- return(0); } //+------------------------------------------------------------------+ void AdjustTrail() // the code for a trailerstop { for(int b = OrdersTotal()-1;b >= 0;b--) // starts a loop by the open orders { if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) // selects the open trades if(OrderMagicNumber()==magicnumber) // if magicnumber is magicnumber if (OrderSymbol()==Symbol()) // if symbol is symbol if(OrderType()==OP_BUY) // if order is a buy order if(Bid-OrderOpenPrice()>(30)*pips) // if bidprice - orderopenprice is greater then 30 points(when there is a [profit) if(OrderStopLoss()<Bid-pips*20) // if the stoploss is smaller then bidprice - 20 points OrderModify(OrderTicket(),OrderOpenPrice(),Bid-(pips*20),OrderTakeProfit(),0,CLR_NONE); // change trailer stop if( buylevel<OrderTakeProfit()) // if buylevel is smaller then takeprofit buylevel = Close[0]-10*pips; // buylevel is close - 10 points }}
Hello again
I have adjust mine pyramide code.
I have put in a lowprice so you can deside untill which level your robot wil trade.
This wil work fine for usa stock with 2 digits.
I have one question about the use of pips.
I have tried to use point instead and it seemes to work as well on mine account. To they work the same?
All comments are welcom
double pips; extern static double buylevel = 30; // Close must be under buylevel before place a buy extern double maxprice = 30; // The price must be below maxprice extern double lowprice = 10; // The price must be above lowprice extern double magicnumber = 1903; // each chart must have a different magicnumber //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- double ticksize = MarketInfo(Symbol(),MODE_TICKSIZE); // By using pips the ea can be used on different brookers (3 or 5 digits) if(ticksize ==0.0001||ticksize ==0.001) pips = ticksize * 10; else pips = ticksize; //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- AdjustTrail(); // Check if the trailer stop can be used static double buylevel = 10000000; // Start with a random number to get 1 buy order if(OrdersTotal()<=10000000) // make sure you can always place a buy order { double a = iMA(NULL,1,5,0,0,0,1); // making use of the moving average double b = Close[0]; // b = Close if (b<a) // if close is smaller than moving average if (Close[0]<buylevel) // if close is smaller than buylevel if (Close[0]>lowprice) // if close is greater than the lowprice (this way you can stop buying at the lowprice) {OrderSend(Symbol(),OP_BUY,0.01,Ask,3,0,0,NULL,magicnumber,0,Green); // this will place the buyorder if (Close[0] >= buylevel) // if close is greater then buylevel return (false); // do nothing buylevel=Close[0]-10*pips; // and else buylevel is the price of close - 10 points return(true); // change buylevel in new price }} else if(OrdersTotal()<=10000000) // else start with a random number { if(b<a) // if close is smaller than moving average if (Close[0]>buylevel+20*pips) // if close is greater then buylevel + 20 points if (Close[0]>lowprice) // if close is greater than the lowprice (this way you can stop buying at the lowprice) {OrderClose(magicnumber,0.01,Ask,3,Blue); // if true then sell buyorder if (Close[0]<=buylevel) // if close smaller or equaal to buylevel return (false); // do nothing buylevel=Close[0]-10*pips; // else buylevel is the price of close - 10 points return(true); // change buylevel in new price }} if (OrdersTotal()==0) // if there are no orders open buylevel=maxprice; // then buylevel is maxprice return(true); // change buylevel in maxprice //---- return(0); } //+------------------------------------------------------------------+ void AdjustTrail() // the code for a trailerstop { for(int b = OrdersTotal()-1;b >= 0;b--) // starts a loop by the open orders { if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) // selects the open trades if(OrderMagicNumber()==magicnumber) // if magicnumber is magicnumber if (OrderSymbol()==Symbol()) // if symbol is symbol if(OrderType()==OP_BUY) // if order is a buy order if(Bid-OrderOpenPrice()>(30)*pips) // if bidprice - orderopenprice is greater then 30 points(when there is a [profit) if(OrderStopLoss()<Bid-pips*20) // if the stoploss is smaller then bidprice - 20 points OrderModify(OrderTicket(),OrderOpenPrice(),Bid-(pips*20),OrderTakeProfit(),0,CLR_NONE); // change trailer stop if( buylevel<OrderTakeProfit()) // if buylevel is smaller then takeprofit buylevel = Close[0]-10*pips; // buylevel is close - 10 points }}
hello again another update.
Try it first on your tester before using.
I would like to make a script or program code whitin this program that calculates your possible biggest lost.
Still trying to make it better any idees are welcome.
double pips; extern static double buylevel = 30; // Close must be under buylevel before place a buy extern double maxprice = 30; // The price must be below maxprice extern double lowprice = 10; // The price must be above lowprice extern double magicnumber = 1903; // each chart must have a different magicnumber extern double steplevel = 10; // every next buy after the first is close - steplevel extern double trailerpoints = 10; // this wil set your trailerpoints extern double timechart = 1; // here you can select your timechart extern double maperiod = 5; // you can select the period for your ma //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- double ticksize = MarketInfo(Symbol(),MODE_TICKSIZE); // By using pips the ea can be used on different brookers (4 or 5 digits) if(ticksize ==0.0001||ticksize ==0.001) pips = ticksize * 10; else pips = ticksize; //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- AdjustTrail(); // Check if the trailer stop can be used static double buylevel = 10000000; // Start with a random number to get 1 buy order if(OrdersTotal()<=10000000) // make sure you can always place a buy order { double a = iMA(NULL,timechart,maperiod,0,0,0,1); // making use of the moving average double b = Close[0]; // b = Close if (b<a) // if close is smaller than moving average if (Close[0]<buylevel) // if close is smaller than buylevel if (Close[0]>lowprice) // if close is greater than the lowprice (this way you can stop buying at the lowprice) {OrderSend(Symbol(),OP_BUY,0.01,Ask,3,0,0,NULL,magicnumber,0,Green); // this will place the buyorder if (Close[0] >= buylevel) // if close is greater then buylevel return (false); // do nothing buylevel=Close[0]-steplevel*pips; // and else buylevel is the price of close - 10 points return(true); // change buylevel in new price }} else if(OrdersTotal()<=10000000) // else start with a random number { if(b<a) // if close is smaller than moving average if (Close[0]>buylevel+trailerpoints*pips) // if close is greater then buylevel + 20 points if (Close[0]>lowprice) // if close is greater than the lowprice (this way you can stop buying at the lowprice) {OrderClose(magicnumber,0.01,Ask,3,Blue); // if true then sell buyorder if (Close[0]<=buylevel) // if close smaller or equaal to buylevel return (false); // do nothing buylevel=Close[0]-steplevel*pips; // else buylevel is the price of close - 10 points return(true); // change buylevel in new price }} if (OrdersTotal()==0) // if there are no orders open buylevel=maxprice; // then buylevel is maxprice return(true); // change buylevel in maxprice //---- return(0); } //+------------------------------------------------------------------+ void AdjustTrail() // the code for a trailerstop { for(int b = OrdersTotal()-1;b >= 0;b--) // starts a loop by the open orders { if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) // selects the open trades if(OrderMagicNumber()==magicnumber) // if magicnumber is magicnumber if (OrderSymbol()==Symbol()) // if symbol is symbol if(OrderType()==OP_BUY) // if order is a buy order if(Bid-OrderOpenPrice()>(steplevel+trailerpoints)*pips) // if bidprice - orderopenprice is greater then steplevel+trailerpoint(when there is a [profit) if(OrderStopLoss()<Bid-pips*trailerpoints) // if the stoploss is smaller then bidprice - trailerpoint OrderModify(OrderTicket(),OrderOpenPrice(),Bid-(pips*trailerpoints),OrderTakeProfit(),0,CLR_NONE); // change trailer stop if( buylevel<OrderTakeProfit()) // if buylevel is smaller then takeprofit buylevel = Close[0]-steplevel*pips; // buylevel is close - 10 points }}
hello
The ea works just fine but i have got stilll one problem that i can't figure out.
When i start up the program again the ea that are on the charts all buy one order and after that it just works fine.
I don't want the computer on or on sleepstand all the time.
So if some one can help me out that would be nice.
Thanks
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello
My name is Donald.
This ea works fine one a single chart.
i use it on the small chart like petrolbars (with a value of max 25 ) so mine highest lost will be about 500 euro.
But what i would like is that this ea will work on several chart at the same time.
i hope that someone would like to fix this problem.
Thanks
double pips;