Coding help - page 439

 
neverbeast:
Hello again.

So I've made simple indicator with arrows. Unfortunately it's not drawing them as I wanted to. My goal was showing an arrow when conditions are met but when conditions aren't met anymore it should delete that arrow. As an example: In 15 seconds of current candle conditions are met and it draws an arrow then it changed direction and conditions aren't met anymore so it should delete that arrow before close of current candle. Currently it draws arrows when conditions are met and doesn't repaint at all, plus there are expiration arrows showing if it went ITM or OTM/ATM that are not drawing at all till refresh. Could someone take a look and help me fix it, please?

6s.mq4

You do not have a check for the first 15 seconds in the code at all. Why don't you add that check too

 
mladen:
You do not have a check for the first 15 seconds in the code at all. Why don't you add that check too

My bad. It was another version of that indicator I was describing here. Anyway I'm newbie at coding mql4 and have no idea how to do that. May you write that piece of code with little tutorial how it works?

 
neverbeast:
My bad. It was another version of that indicator I was describing here. Anyway I'm newbie at coding mql4 and have no idea how to do that. May you write that piece of code with little tutorial how it works?

You can do this :

if (TimeCurrent()-Time[0])>15) return(0);

Place it at the beginning of the start() procedure (as a first line in it) and it will prevent the rest of the code to be executed if the number of seconds passed from the beginning of the current candle is greater than 15

 

I have the code for an EA but my skills are.....none. Tried to compile it, get the bugs out but no luck.

Anyone able to help ??

//|$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ // Price Action V1 // hodhabi@gmail.com //|$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ #define NL "\n" extern double Lots = 1; extern double TP = 100; extern int TradeType = 0; // 0 to follow the trend, 1 to force buy, 2 to force sell extern int leverage = 5; extern double MaximumLossinMoney = 1000; extern int MagicNumber = 250346; extern bool UseAlerts = false; //+-------------+ //| Custom init | //|-------------+ int init() { } //+----------------+ //| Custom DE-init | //+----------------+ int deinit() { } void sendEmail() { if (UseAlerts==true) SendMail("YTF Alert", "New order has been added "+OrdersTotal()+" Balance = " +AccountBalance() + " Equity = "+AccountEquity() +" Current Price: " + Close[0]); return; } void DrawHorizentalLine() { ObjectCreate("TProfit", OBJ_HLINE, 0, Time[1], Close[0]+500*Point); ObjectSet("Tprofit", OBJPROP_STYLE, STYLE_SOLID); ObjectSet("Tprofit", OBJPROP_COLOR, MediumSeaGreen); } //+------------------------------------------------------------------------+ //| Closes everything //+------------------------------------------------------------------------+ void CloseAll() { for(int i=OrdersTotal()-1;i>=0;i--) { OrderSelect(i, SELECT_BY_POS); bool result = false; if ( OrderType() == OP_BUY && OrderMagicNumber()== MagicNumber) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red ); if ( OrderType() == OP_SELL && OrderMagicNumber()==MagicNumber) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red ); if (UseAlerts) PlaySound("alert.wav"); } return; } void CloseAllBuy() { for(int i=OrdersTotal()-1;i>=0;i--) { OrderSelect(i, SELECT_BY_POS); bool result = false; if ( OrderType() == OP_BUY && OrderMagicNumber()==MagicNumber) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red ); if (UseAlerts) PlaySound("alert.wav"); } return; } void CloseAllSell() { for(int i=OrdersTotal()-1;i>=0;i--) { OrderSelect(i, SELECT_BY_POS); bool result = false; if ( OrderType() == OP_SELL && OrderMagicNumber()==MagicNumber) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red ); if (UseAlerts) PlaySound("alert.wav"); } return; } //+------------------------------------------------------------------------+ //| cancels all orders that are in profit //+------------------------------------------------------------------------+ //+------------------------------------------------------------------------+ //| cancels all pending orders //+------------------------------------------------------------------------+ //+-----------+ //| Main | //+-----------+ int start() { int OrdersBUY, ticket; int OrdersSELL; double BuyLots, SellLots, BuyProfit, SellProfit; //+------------------------------------------------------------------+ // Determine last order price | //-------------------------------------------------------------------+ if(OrdersTotal()==0 && TradeType ==1 ) { ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-TP*Point,Ask+leverage*TP*Point,"MLTrendETF",MagicNumber,0,Green); TradeType=2; if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) sendEmail(); } else Print("Error opening BUY order : ",GetLastError()); return(0); } if(OrdersTotal()==0 && TradeType ==2) { ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+TP*Point,Bid-TP*leverage*Point,"MLTrendETF",MagicNumber,0,Green); TradeType = 1; if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) sendEmail(); } else Print("Error opening BUY order : ",GetLastError()); return(0); } } // start()

 

Sorry, here it is not all jumbled up

//|$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ // Price Action V1 // hodhabi@gmail.com //|$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ #define NL "\n" extern double Lots = 1; extern double TP = 100; extern int TradeType = 0; // 0 to follow the trend, 1 to force buy, 2 to force sell extern int leverage = 5; extern double MaximumLossinMoney = 1000; extern int MagicNumber = 250346; extern bool UseAlerts = false; //+-------------+ //| Custom init | //|-------------+ int init() { } //+----------------+ //| Custom DE-init | //+----------------+ int deinit() { } void sendEmail() { if (UseAlerts==true) SendMail("YTF Alert", "New order has been added "+OrdersTotal()+" Balance = " +AccountBalance() + " Equity = "+AccountEquity() +" Current Price: " + Close[0]); return; } void DrawHorizentalLine() { ObjectCreate("TProfit", OBJ_HLINE, 0, Time[1], Close[0]+500*Point); ObjectSet("Tprofit", OBJPROP_STYLE, STYLE_SOLID); ObjectSet("Tprofit", OBJPROP_COLOR, MediumSeaGreen); } //+------------------------------------------------------------------------+ //| Closes everything //+------------------------------------------------------------------------+ void CloseAll() { for(int i=OrdersTotal()-1;i>=0;i--) { OrderSelect(i, SELECT_BY_POS); bool result = false; if ( OrderType() == OP_BUY && OrderMagicNumber()== MagicNumber) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red ); if ( OrderType() == OP_SELL && OrderMagicNumber()==MagicNumber) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red ); if (UseAlerts) PlaySound("alert.wav"); } return; } void CloseAllBuy() { for(int i=OrdersTotal()-1;i>=0;i--) { OrderSelect(i, SELECT_BY_POS); bool result = false; if ( OrderType() == OP_BUY && OrderMagicNumber()==MagicNumber) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red ); if (UseAlerts) PlaySound("alert.wav"); } return; } void CloseAllSell() { for(int i=OrdersTotal()-1;i>=0;i--) { OrderSelect(i, SELECT_BY_POS); bool result = false; if ( OrderType() == OP_SELL && OrderMagicNumber()==MagicNumber) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red ); if (UseAlerts) PlaySound("alert.wav"); } return; } //+------------------------------------------------------------------------+ //| cancels all orders that are in profit //+------------------------------------------------------------------------+ //+------------------------------------------------------------------------+ //| cancels all pending orders //+------------------------------------------------------------------------+ //+-----------+ //| Main | //+-----------+ int start() { int OrdersBUY, ticket; int OrdersSELL; double BuyLots, SellLots, BuyProfit, SellProfit; //+------------------------------------------------------------------+ // Determine last order price | //-------------------------------------------------------------------+ if(OrdersTotal()==0 && TradeType ==1 ) { ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-TP*Point,Ask+leverage*TP*Point,"MLTrendETF",MagicNumber,0,Green); TradeType=2; if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) sendEmail(); } else Print("Error opening BUY order : ",GetLastError()); return(0); } if(OrdersTotal()==0 && TradeType ==2) { ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+TP*Point,Bid-TP*leverage*Point,"MLTrendETF",MagicNumber,0,Green); TradeType = 1; if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) sendEmail(); } else Print("Error opening BUY order : ",GetLastError()); return(0); } } // start()

 
godrich:
Sorry, here it is not all jumbled up //|$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ // Price Action V1 // hodhabi@gmail.com //|$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ #define NL "\n" extern double Lots = 1; extern double TP = 100; extern int TradeType = 0; // 0 to follow the trend, 1 to force buy, 2 to force sell extern int leverage = 5; extern double MaximumLossinMoney = 1000; extern int MagicNumber = 250346; extern bool UseAlerts = false; //+-------------+ //| Custom init | //|-------------+ int init() { } //+----------------+ //| Custom DE-init | //+----------------+ int deinit() { } void sendEmail() { if (UseAlerts==true) SendMail("YTF Alert", "New order has been added "+OrdersTotal()+" Balance = " +AccountBalance() + " Equity = "+AccountEquity() +" Current Price: " + Close[0]); return; } void DrawHorizentalLine() { ObjectCreate("TProfit", OBJ_HLINE, 0, Time[1], Close[0]+500*Point); ObjectSet("Tprofit", OBJPROP_STYLE, STYLE_SOLID); ObjectSet("Tprofit", OBJPROP_COLOR, MediumSeaGreen); } //+------------------------------------------------------------------------+ //| Closes everything //+------------------------------------------------------------------------+ void CloseAll() { for(int i=OrdersTotal()-1;i>=0;i--) { OrderSelect(i, SELECT_BY_POS); bool result = false; if ( OrderType() == OP_BUY && OrderMagicNumber()== MagicNumber) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red ); if ( OrderType() == OP_SELL && OrderMagicNumber()==MagicNumber) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red ); if (UseAlerts) PlaySound("alert.wav"); } return; } void CloseAllBuy() { for(int i=OrdersTotal()-1;i>=0;i--) { OrderSelect(i, SELECT_BY_POS); bool result = false; if ( OrderType() == OP_BUY && OrderMagicNumber()==MagicNumber) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red ); if (UseAlerts) PlaySound("alert.wav"); } return; } void CloseAllSell() { for(int i=OrdersTotal()-1;i>=0;i--) { OrderSelect(i, SELECT_BY_POS); bool result = false; if ( OrderType() == OP_SELL && OrderMagicNumber()==MagicNumber) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red ); if (UseAlerts) PlaySound("alert.wav"); } return; } //+------------------------------------------------------------------------+ //| cancels all orders that are in profit //+------------------------------------------------------------------------+ //+------------------------------------------------------------------------+ //| cancels all pending orders //+------------------------------------------------------------------------+ //+-----------+ //| Main | //+-----------+ int start() { int OrdersBUY, ticket; int OrdersSELL; double BuyLots, SellLots, BuyProfit, SellProfit; //+------------------------------------------------------------------+ // Determine last order price | //-------------------------------------------------------------------+ if(OrdersTotal()==0 && TradeType ==1 ) { ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-TP*Point,Ask+leverage*TP*Point,"MLTrendETF",MagicNumber,0,Green); TradeType=2; if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) sendEmail(); } else Print("Error opening BUY order : ",GetLastError()); return(0); } if(OrdersTotal()==0 && TradeType ==2) { ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+TP*Point,Bid-TP*leverage*Point,"MLTrendETF",MagicNumber,0,Green); TradeType = 1; if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) sendEmail(); } else Print("Error opening BUY order : ",GetLastError()); return(0); } } // start()

godrich

can yo attach the mq4 file

This way it will be unusable if pasted into metaeditor

 

Not sure if this worked but...

Files:
pac.mq4  5 kb
 

Hi.

I just found the PetD indicator whic draw a red or green line over my candlestick. What i wonder is if it is any possibilities to make a strip of colored histogram instead.

So i can have a seperate window with either a green or a red bar.

Thanks

pet-d_full_option.mq4

Files:
 
NWFstudent:
Hi.

I just found the PetD indicator whic draw a red or green line over my candlestick. What i wonder is if it is any possibilities to make a strip of colored histogram instead.

So i can have a seperate window with either a green or a red bar.

Thanks

pet-d_full_option.mq4

NWFstudent

Here is that type too : pet-d_full_option_-_separate.mq4

 
makototokyo:
Hello,

this indicator doesn't seem to make alert well. I feel like it makes alert only once after the mt4 is started and after the 1st alert it doesn't make sound. I also realized that it makes sound only when the bar is "climax".. but I want it to make sound when the bar is "rising".

Could anyone fix this code for the volume indicator?

if you have time to do the same for this candle indicator I appreciate that, but I don't wanna take too much of your time.

Thank you in advance.

Makototokyo, changed the alerts out in the separate window version to use "bull rising and bear rising" alerts, and they should be working correctly in this version.

Reason: