[Need help] To run an EA on one bar chart only

 

Hello,

I'm a novice at trading with MT4 and it's Expert Advisors. I downloaded several EA's and installed them. One of them gives really nice results on the Eur/Usd M5 chart (when backtracked in the tester). On the M15 chart however the results aren't that good.

When i turn the EA on, the EA apperas in all the charts of Eur/Usd. I just want to have it operate on the M5 chart. Is that possible, and if so, how do i set it up?

Kind regards Mario

 

show your code we might be able to help u

 

Mario123:

I just want to have it operate on the M5 chart.

Then only run it on the M15 chart. Whats the problem?
 

then use it on which chart u like

 
qjol:

then use it on which chart u like


When i turn the EA on, it runs on all the charts. I cannot disable it on for example the M1 or M15. When i run the code in the Tester it performs well on the M5 but not on the M15. This is the code:

//+------------------------------------------------------------------+

//+ See http://www.fx1.net/codelibrary.php for more MetaTrader code +

//+ More then 3000 files ready to download for free. +

//+------------------------------------------------------------------+

//+------------------------------------------------------------------+


//| 100 pips a day.mq4 |


//| Copyright © 2005, MetaQuotes Software Corp. |


//| https://www.metaquotes.net// |


//+------------------------------------------------------------------+


#property copyright "Copyright © 2005, MetaQuotes Software Corp."


#property link "https://www.metaquotes.net//"

extern double lTakeProfit = 31;


extern double sTakeProfit = 35;


extern double lTrailingStop = 22;


extern double sTrailingStop = 19;


extern color clOpenBuy = Blue;


extern color clCloseBuy = Aqua;


extern color clOpenSell = Red;


extern color clCloseSell = Violet;


extern color clModiBuy = Blue;


extern color clModiSell = Red;


extern string Name_Expert = "Generate from Gordago";


extern int Slippage = 2;


extern bool UseSound = False;


extern string NameFileSound = "alert.wav";


extern double Lots = 0.2;


void deinit() {


Comment("");


}


//+------------------------------------------------------------------+


//| |


//+------------------------------------------------------------------+


int start(){


if(Bars<100){


Print("bars less than 100");


return(0);


}


if(lTakeProfit<10){


Print("TakeProfit less than 10");


return(0);


}


if(sTakeProfit<10){


Print("TakeProfit less than 10");


return(0);


}

double diClose0=iClose(NULL,5,0);


double diMA1=iMA(NULL,5,7,0,MODE_SMA,PRICE_OPEN,0);


double diClose2=iClose(NULL,5,0);


double diMA3=iMA(NULL,5,6,0,MODE_SMA,PRICE_OPEN,0);

if(AccountFreeMargin()<(1000*Lots)){


Print("We have no money. Free Margin = ", AccountFreeMargin());


return(0);


}


if (!ExistPositions()){

if ((diClose0<diMA1)){


OpenBuy();


return(0);


}

if ((diClose2>diMA3)){


OpenSell();


return(0);


}


}


TrailingPositionsBuy(lTrailingStop);


TrailingPositionsSell(sTrailingStop);


return (0);


}

bool ExistPositions() {


for (int i=0; i<OrdersTotal(); i++) {


if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {


if (OrderSymbol()==Symbol()) {


return(True);


}


}


}


return(false);


}


void TrailingPositionsBuy(int trailingStop) {


for (int i=0; i<OrdersTotal(); i++) {


if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {


if (OrderSymbol()==Symbol()) {


if (OrderType()==OP_BUY) {


if (Bid-OrderOpenPrice()>trailingStop*Point) {


if (OrderStopLoss()<Bid-trailingStop*Point)


ModifyStopLoss(Bid-trailingStop*Point);


}


}


}


}


}


}


void TrailingPositionsSell(int trailingStop) {


for (int i=0; i<OrdersTotal(); i++) {


if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {


if (OrderSymbol()==Symbol()) {


if (OrderType()==OP_SELL) {


if (OrderOpenPrice()-Ask>trailingStop*Point) {


if (OrderStopLoss()>Ask+trailingStop*Point ||


OrderStopLoss()==0)


ModifyStopLoss(Ask+trailingStop*Point);


}


}


}


}


}


}


void ModifyStopLoss(double ldStopLoss) {


bool fm;


fm = OrderModify(OrderTicket(),OrderOpenPrice


(),ldStopLoss,OrderTakeProfit(),0,CLR_NONE);


if (fm && UseSound) PlaySound(NameFileSound);


}

void OpenBuy() {


double ldLot, ldStop, ldTake;


string lsComm;


ldLot = GetSizeLot();


ldStop = 0;


ldTake = GetTakeProfitBuy();


lsComm = GetCommentForOrder();


OrderSend(Symbol


(),OP_BUY,ldLot,Ask,Slippage,ldStop,ldTake,lsComm,0,0,clOpenBuy);


if (UseSound) PlaySound(NameFileSound);


}


void OpenSell() {


double ldLot, ldStop, ldTake;


string lsComm;

ldLot = GetSizeLot();


ldStop = 0;


ldTake = GetTakeProfitSell();


lsComm = GetCommentForOrder();


OrderSend(Symbol


(),OP_SELL,ldLot,Bid,Slippage,ldStop,ldTake,lsComm,0,0,clOpenSell);


if (UseSound) PlaySound(NameFileSound);


}


string GetCommentForOrder() { return(Name_Expert); }


double GetSizeLot() { return(Lots); }


double GetTakeProfitBuy() { return(Ask+lTakeProfit*Point); }


double GetTakeProfitSell() { return(Bid-sTakeProfit*Point); }

 
Mario, I suggest you attach the code as a file.
 
i still dont understand what you mean by "runs on all charts". If you want it to run on M15 then simply attach it to an M15 chart and not to any other chart and don't switch timeframe on that chart while it is running. Whats the problem?
 

Anyway it is written for 5 minutes I don't know how you test it for 15 minutes

double diClose0=iClose(NULL,5,0);
double diMA1=iMA(NULL,5,7,0,MODE_SMA,PRICE_OPEN,0);
double diClose2=iClose(NULL,5,0);
double diMA3=iMA(NULL,5,6,0,MODE_SMA,PRICE_OPEN,0);

this is for 15:

double diClose0=iClose(NULL,15,0);
double diMA1=iMA(NULL,15,7,0,MODE_SMA,PRICE_OPEN,0);
double diClose2=iClose(NULL,15,0);
double diMA3=iMA(NULL,15,6,0,MODE_SMA,PRICE_OPEN,0);
 
qjol:

Anyway it is written for 5 minutes I don't know how you test it for 15 minutes

this is for 15:

This has nothing to do on which chart it runs. I suggest you learn a bit more about calls to the iXxxxx() functions before you throw around wild and unfounded speculations and give wrong and misleading answers. You can call iMA() (as well as any other built in or custom indicator) for any timeframe from any other timeframe. Otherwise there would be no need for the timeframe as function argument.


Also this has nothing to do with the OP's question. He wants to run it on M5 so he just needs to attach it to an M5 chart and remove it from all other charts and don't switch the timeframe on that chart anymore and ignore qjol's wrong answer (this change in the code would be wrong).

Just run it on M5 as it is -> Problem solved.


[edit replaced M15 with M5, same principle applies. The iMA() has nothing to do with it]

 
7bit:
This has nothing to do on which chart it runs. You can call iMA() (as well as any other built in or custom indicator) for any timeframe from any other timeframe. Otherwise there would be no need for the timeframe as function argument. Also this has nothing to do with the OPs question. He wants to run it on M15 so he just needs to attach it to an M15 chart and remove it from all other charts and don't switch the timeframe on that chart anymore. Problem solved.

Read the whole post
 
qjol:

Read the whole post
I read it. Your answer is wrong.
Reason: