//ROC1 input param...GLOBAL VARIABLE int RPeriod=10; bool UsePercent=false; //+---------------------------------------------------------+ void OnTick(){ //-----check result of custom function if(Cross()>0 && OTHER_SIGNAL...){OpenBuyOrder...} if(Cross()<0 && OTHER_SIGNAL...){OpenSellOrder...} }//OnTick() //+---------------------------------------------------------+ //Custom function int Cross(){ ROC_2=iCustom(Symbol(),0,"ROC1",RPeriod,UsePercent,0,2); ROC_1=iCustom(Symbol(),0,"ROC1",RPeriod,UsePercent,0,1); if(ROC_2<=0 && ROC_1>0){return(1);} if(ROC_2>=0 && ROC_1<0){return(-1);} return(0); }
Chad Magruder:
//+------------------------------------------------------------------+ //| FLFXAuto.mq4 | //| Freedomlifefx | //| https://freedomlifefx.com | //+------------------------------------------------------------------+ #property copyright "Freedomlifefx" #property link "https://freedomlifefx.com" #property version "1.00" #property strict int RPeriod=20; bool UsePercent=false; //Custom function int Cross(){ ROC_2=iCustom(NULL,0,"ROC1",RPeriod,UsePercent,0,2); ROC_1=iCustom(NULL,0,"ROC1",RPeriod,UsePercent,0,1); if(ROC_2<=0 && ROC_1>0){return(1);} if(ROC_2>=0 && ROC_1<0){return(-1);} return(0); } //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //Buy: when current line is up and blue and previous line is down and red double buy_hmacurrent = iCustom(NULL, 0, "hma-trend-indicator", 30,3,0, 0, 0); double buy_hmaprevious = iCustom(NULL, 0, "hma-trend-indicator", 30,3,0, 0, 1); //Sell: when current line is down and red and previous line is up and blue double sell_hmacurrent = iCustom(NULL, 0, "hma-trend-indicator", 30, 3, 0, 1, 0); double sell_hmaprevious = iCustom(NULL, 0, "hma-trend-indicator", 30, 3, 0, 1, 1); // Here, we fetch the current 3-period ATR value double atr = iATR(NULL, 0, 14, 0); // Since the stop loss will be a multiple of this ATR value, // we define this multiple. 2.5 times the ATR value // is often a good start: double atrMultiple = 3; // Now, we set our stop loss. // We multiply the ATR value by the ATR multiple // and divide by the Point constant // in order to get a value in points: int stopLoss = (int)(atr * atrMultiple / Point); // And, since we have a dynamic stop loss value, // it makes sense to use the same pips amount as our take profit int takeProfit = stopLoss; // Dynamic lot sizes based on our stop loss double lots = calculateLotSize(stopLoss); // Buy Rules if (sell_hmaprevious!=EMPTY_VALUE && sell_hmacurrent==EMPTY_VALUE && buy_hmacurrent!=EMPTY_VALUE && Cross()>0) { if (OrderSend(Symbol(), OP_BUY, lots, Ask, 3, Ask - stopLoss * Point, Ask + takeProfit * Point, "my forex wall-e order", 12345, 0, Green)) { Print("Buy order succeeded!"); } } // Sell Rules if(buy_hmaprevious!=EMPTY_VALUE && buy_hmacurrent==EMPTY_VALUE && sell_hmacurrent!=EMPTY_VALUE && Cross()<0) { if (OrderSend(Symbol(), OP_SELL, lots, Bid, 3, Bid + stopLoss * Point, Bid - takeProfit * Point, "my forex wall-e order", 12345, 0, Red)) { Print("Sell order succeeded!"); } } } //+------------------------------------------------------------------+ /** * Calculate the amount of lots needed based on stop loss * * @return double */ double calculateLotSize(int StopLossPoints) { // 1% risk per trade int risk = 2; double lotStep = MarketInfo(Symbol(), MODE_LOTSTEP); double minLot = MarketInfo(Symbol(), MODE_MINLOT); double maxLot = MarketInfo(Symbol(), MODE_MAXLOT); double tickVal = MarketInfo(Symbol(), MODE_TICKVALUE); double lotSize = AccountBalance() * risk / 100 / (StopLossPoints * tickVal); return MathMin( maxLot, MathMax( minLot, NormalizeDouble(lotSize / lotStep, 0) * lotStep // This rounds the lotSize to the nearest lotstep interval ) ); }This is the code. But i get these Errors :
Files:
Capture.PNG
13 kb
int Cross(){
double
ROC_2=iCustom(NULL,0,"ROC1",RPeriod,UsePercent,0,2),
ROC_1=iCustom(NULL,0,"ROC1",RPeriod,UsePercent,0,1);
if(ROC_2<=0 && ROC_1>0){return(1);}
if(ROC_2>=0 && ROC_1<0){return(-1);}
return(0);
}
double
ROC_2=iCustom(NULL,0,"ROC1",RPeriod,UsePercent,0,2),
ROC_1=iCustom(NULL,0,"ROC1",RPeriod,UsePercent,0,1);
if(ROC_2<=0 && ROC_1>0){return(1);}
if(ROC_2>=0 && ROC_1<0){return(-1);}
return(0);
}
sdlg:
int Cross(){
double
ROC_2=iCustom(NULL,0,"ROC1",RPeriod,UsePercent,0,2),
ROC_1=iCustom(NULL,0,"ROC1",RPeriod,UsePercent,0,1);
if(ROC_2<=0 && ROC_1>0){return(1);}
if(ROC_2>=0 && ROC_1<0){return(-1);}
return(0);
}
int Cross(){
double
ROC_2=iCustom(NULL,0,"ROC1",RPeriod,UsePercent,0,2),
ROC_1=iCustom(NULL,0,"ROC1",RPeriod,UsePercent,0,1);
if(ROC_2<=0 && ROC_1>0){return(1);}
if(ROC_2>=0 && ROC_1<0){return(-1);}
return(0);
}
Thank you !
But its not opening any trades at all now. 0 error and o warnings
// Buy Rules if (Cross()>0 && sell_hmaprevious!=EMPTY_VALUE && sell_hmacurrent==EMPTY_VALUE && buy_hmacurrent!=EMPTY_VALUE) { if (OrderSend(Symbol(), OP_BUY, lots, Ask, 3, Ask - stopLoss * Point, Ask + takeProfit * Point, "my forex wall-e order", 12345, 0, Green)) { Print("Buy order succeeded!"); } } // Sell Rules if(Cross()<0 && buy_hmaprevious!=EMPTY_VALUE && buy_hmacurrent==EMPTY_VALUE && sell_hmacurrent!=EMPTY_VALUE) { if (OrderSend(Symbol(), OP_SELL, lots, Bid, 3, Bid + stopLoss * Point, Bid - takeProfit * Point, "my forex wall-e order", 12345, 0, Red)) { Print("Sell order succeeded!"); } }
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
#solved