/* !xMeter.mq4 Copyright © 2007, MetaQuotes Software Corp. Price Meter System™ ©GPL */ #property copyright "x Meter System™ ©GPL" #property link "forex-tsd dot com" #define ARRSIZE 12 // number of pairs !!!DON'T CHANGE THIS NUMBER!!! #define PAIRSIZE 7 // number of currencies !!!DON'T CHANGE THIS NUMBER!!! #define TABSIZE 10 // scale of currency's power !!!DON'T CHANGE THIS NUMBER!!! #define ORDER 2 // available type of order !!!DON'T CHANGE THIS NUMBER!!! #define AUDUSD 2 #define EURAUD 9 #define EURCHF 8 #define EURGBP 7 #define EURJPY 6 #define EURUSD 0 #define GBPCHF 11 #define GBPJPY 10 #define GBPUSD 1 #define USDCAD 5 #define USDCHF 4 #define USDJPY 3 //Bars must be <= and >= to the set values for order entry //Exit is when both have crossed over (e.g. exit long when values are BarLow) extern double BarHigh=5.0; extern double BarLow=4.0; extern bool mm=true; extern bool AccountIsMicro=false; extern double TradeSizePercent=0.2; extern double Lots=0.1; int Magic=05162007; string TradePair; double OrderBid, OrderAsk; //+------------------------------------------------------------------+ // expert initialization function | //+------------------------------------------------------------------+ int init() { int err,lastError; //---- initGraph(); while (true) // infinite loop for main program { if (IsConnected()) main(); if (!IsConnected()) objectBlank(); WindowRedraw(); Sleep(1000); // give your PC a breath } //---- return(0); // end of init function } //+------------------------------------------------------------------+ // expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- ObjectsDeleteAll(0,OBJ_LABEL); Print("shutdown error - ",GetLastError()); // system is detached from platform //---- return(0); // end of deinit function } //+------------------------------------------------------------------+ // expert start function | //+------------------------------------------------------------------+ int start() { //---- //---- return(0); // end of start funtion } double LotsOptimized() { if(mm==false) return(Lots); double lot=Lots; int decimalPlaces=1; if(AccountIsMicro==true) decimalPlaces=2; lot=NormalizeDouble(AccountFreeMargin()*TradeSizePercent/1000.0,decimalPlaces); if(lot<0.1 && AccountIsMicro==false) lot=0.1; if(lot<0.01 && AccountIsMicro==true) lot=0.01; if(lot>99) lot=99; return(lot); } //+------------------------------------------------------------------+ // expert custom function | //+------------------------------------------------------------------+ void main() // this a control center { //---- string aPair[ARRSIZE] = {"EURUSD","GBPUSD","AUDUSD","USDJPY","USDCHF","USDCAD", "EURJPY","EURGBP","EURCHF","EURAUD","GBPJPY","GBPCHF"}; string aMajor[PAIRSIZE] = {"USD","EUR","GBP","CHF","CAD","AUD","JPY"}; string aOrder[ORDER] = {"BUY ","SELL "}; double aMeter[PAIRSIZE]; double aHigh[ARRSIZE]; double aLow[ARRSIZE]; double aBid[ARRSIZE]; double aAsk[ARRSIZE]; double aRatio[ARRSIZE]; double aRange[ARRSIZE]; double aLookup[ARRSIZE]; double aStrength[ARRSIZE]; double point; int index, i, j; for (index = 0; index < ARRSIZE; index++) // initialize all pairs required value { RefreshRates(); // refresh all currency's instrument point = MarketInfo(aPair[index],MODE_POINT); // get a point basis aHigh[index] = MarketInfo(aPair[index],MODE_HIGH); // set a high today aLow[index] = MarketInfo(aPair[index],MODE_LOW); // set a low today aBid[index] = MarketInfo(aPair[index],MODE_BID); // set a last bid aAsk[index] = MarketInfo(aPair[index],MODE_ASK); // set a last ask aRange[index] = MathMax((aHigh[index]-aLow[index])/point,1); // calculate range today aRatio[index] = (aBid[index]-aLow[index])/aRange[index]/point; // calculate pair ratio aLookup[index] = iLookup(aRatio[index]*100); // set a pair grade aStrength[index] = 9-aLookup[index]; // set a pair strengh } // calculate all currencies meter aMeter[0] = NormalizeDouble((aLookup[3]+aLookup[4]+aLookup[5]+aStrength[0]+aStrength[1]+aStrength[2])/6,1); aMeter[1] = NormalizeDouble((aLookup[0]+aLookup[6]+aLookup[7]+aLookup[8]+aLookup[9])/5,1); aMeter[2] = NormalizeDouble((aLookup[1]+aLookup[10]+aLookup[11]+aStrength[7])/4,1); aMeter[3] = NormalizeDouble((aStrength[4]+aStrength[8]+aStrength[11])/3,1); aMeter[4] = NormalizeDouble((aStrength[5]),1); aMeter[5] = NormalizeDouble((aLookup[2]+aStrength[9])/2,1); aMeter[6] = NormalizeDouble((aStrength[3]+aStrength[6]+aStrength[10])/3,1); objectBlank(); paintUSD(aMeter[0]); paintEUR(aMeter[1]); paintGBP(aMeter[2]); paintCHF(aMeter[3]); paintCAD(aMeter[4]); paintAUD(aMeter[5]); paintJPY(aMeter[6]); paintLine(); for (int n=0; n<12; n++) { switch(n) { case 0: i=1; j=0; break; case 1: i=2; j=0; break; case 2: i=5; j=0; break; case 3: i=0; j=6; break; case 4: i=0; j=3; break; case 5: i=0; j=4; break; case 6: i=1; j=6; break; case 7: i=1; j=2; break; case 8: i=1; j=3; break; case 9: i=1; j=5; break; case 10: i=2; j=6; break; case 11: i=2; j=3; break; } //Print("n:",n,",i:",i,",j:",j,",",aPair[n],", ",aMeter[i],",",aMeter[j]); //Count existing orders int Count=0; for (int m=0;m=BarHigh && aMeter[j]<=BarLow) OpenBuy(); if(aMeter[i]<=BarLow && aMeter[j]>=BarHigh) OpenSell(); } //Count orders for this pair and close if necessary for (m=0;mBarLow)) { CheckTradeContext(); OrderClose(OrderTicket(),OrderLots(),aBid[n],3,Red); } if ((OrderType()==OP_SELL) && (OrderSymbol() == aPair[n]) && (OrderMagicNumber() == Magic) && (aMeter[i]>BarLow && aMeter[j] 0) ObjectSet("usd_5",OBJPROP_COLOR,Red); if (value > 2) ObjectSet("usd_4",OBJPROP_COLOR,Orange); if (value > 4) ObjectSet("usd_3",OBJPROP_COLOR,Gold); if (value > 6) ObjectSet("usd_2",OBJPROP_COLOR,YellowGreen); if (value > 7) ObjectSet("usd_1",OBJPROP_COLOR,Lime); ObjectSet("usd",OBJPROP_COLOR,SkyBlue); ObjectSetText("usdp",DoubleToStr(value,1),8,"Arial Narrow",Silver); } void paintEUR(double value) { if (value > 0) ObjectSet("eur_5",OBJPROP_COLOR,Red); if (value > 2) ObjectSet("eur_4",OBJPROP_COLOR,Orange); if (value > 4) ObjectSet("eur_3",OBJPROP_COLOR,Gold); if (value > 6) ObjectSet("eur_2",OBJPROP_COLOR,YellowGreen); if (value > 7) ObjectSet("eur_1",OBJPROP_COLOR,Lime); ObjectSet("eur",OBJPROP_COLOR,SkyBlue); ObjectSetText("eurp",DoubleToStr(value,1),8,"Arial Narrow",Silver); } void paintGBP(double value) { if (value > 0) ObjectSet("gbp_5",OBJPROP_COLOR,Red); if (value > 2) ObjectSet("gbp_4",OBJPROP_COLOR,Orange); if (value > 4) ObjectSet("gbp_3",OBJPROP_COLOR,Gold); if (value > 6) ObjectSet("gbp_2",OBJPROP_COLOR,YellowGreen); if (value > 7) ObjectSet("gbp_1",OBJPROP_COLOR,Lime); ObjectSet("gbp",OBJPROP_COLOR,SkyBlue); ObjectSetText("gbpp",DoubleToStr(value,1),8,"Arial Narrow",Silver); } void paintCHF(double value) { if (value > 0) ObjectSet("chf_5",OBJPROP_COLOR,Red); if (value > 2) ObjectSet("chf_4",OBJPROP_COLOR,Orange); if (value > 4) ObjectSet("chf_3",OBJPROP_COLOR,Gold); if (value > 6) ObjectSet("chf_2",OBJPROP_COLOR,YellowGreen); if (value > 7) ObjectSet("chf_1",OBJPROP_COLOR,Lime); ObjectSet("chf",OBJPROP_COLOR,SkyBlue); ObjectSetText("chfp",DoubleToStr(value,1),8,"Arial Narrow",Silver); } void paintCAD(double value) { if (value > 0) ObjectSet("cad_5",OBJPROP_COLOR,Red); if (value > 2) ObjectSet("cad_4",OBJPROP_COLOR,Orange); if (value > 4) ObjectSet("cad_3",OBJPROP_COLOR,Gold); if (value > 6) ObjectSet("cad_2",OBJPROP_COLOR,YellowGreen); if (value > 7) ObjectSet("cad_1",OBJPROP_COLOR,Lime); ObjectSet("cad",OBJPROP_COLOR,SkyBlue); ObjectSetText("cadp",DoubleToStr(value,1),8,"Arial Narrow",Silver); } void paintAUD(double value) { if (value > 0) ObjectSet("aud_5",OBJPROP_COLOR,Red); if (value > 2) ObjectSet("aud_4",OBJPROP_COLOR,Orange); if (value > 4) ObjectSet("aud_3",OBJPROP_COLOR,Gold); if (value > 6) ObjectSet("aud_2",OBJPROP_COLOR,YellowGreen); if (value > 7) ObjectSet("aud_1",OBJPROP_COLOR,Lime); ObjectSet("aud",OBJPROP_COLOR,SkyBlue); ObjectSetText("audp",DoubleToStr(value,1),8,"Arial Narrow",Silver); } void paintJPY(double value) { if (value > 0) ObjectSet("jpy_5",OBJPROP_COLOR,Red); if (value > 2) ObjectSet("jpy_4",OBJPROP_COLOR,Orange); if (value > 4) ObjectSet("jpy_3",OBJPROP_COLOR,Gold); if (value > 6) ObjectSet("jpy_2",OBJPROP_COLOR,YellowGreen); if (value > 7) ObjectSet("jpy_1",OBJPROP_COLOR,Lime); ObjectSet("jpy",OBJPROP_COLOR,SkyBlue); ObjectSetText("jpyp",DoubleToStr(value,1),8,"Arial Narrow",Silver); } void paintLine() { ObjectSet("line1",OBJPROP_COLOR,DimGray); ObjectSet("line2",OBJPROP_COLOR,DimGray); } void OpenBuy() { int ticket,err; CheckTradeContext(); ticket = OrderSend(TradePair,OP_BUY,LotsOptimized(),OrderAsk,3,0,0,"EA",Magic,0,Red); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice()); } else { Print("Error opening BUY order : ",GetLastError()+" Buy @ "+OrderAsk); //Print("Lots:",Lots,", TP:",TP,", SL:",SL); } } void OpenSell() { int ticket,err; CheckTradeContext(); ticket = OrderSend(TradePair,OP_SELL,LotsOptimized(),OrderBid,3,0,0,"EA",Magic,0,Red); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice()); } else { Print("Error opening SELL order : ",GetLastError()+" Sell @ "+OrderBid); } } void CheckTradeContext() { if(!IsTradeAllowed()) { // Print("Trade context is busy! Wait until it is free..."); // infinite loop while(true) { // if the expert was stopped by the user, stop operation if(IsStopped()) { // Print("The expert was stopped by the user!"); return(-1); } // if trade context has become free, terminate the loop and start trading if(IsTradeAllowed()) { // Print("Trade context has become free!"); break; } // if no loop breaking condition has been met, "wait" for 0.1 sec // and restart checking Sleep(100); } } }