Hi,
I have the following code:
THE EA is called POWERSM (in other forum trading systems area)
I have failed to make this profitable until my recent settings and I realized this is the key. Please see my .set file.
It doesn't matter what time frame you run it on, it doesn't care.
It opens an order (blindly) in one direction. If that is a winner, it continues on in that direction until it loses. At which time it is to reverse each time until it wins.
Well, it works that way on the 'longs', but on the shorts even if it wins it reverses to a 'long'?
Can someone help me figure out this as it is beyond my ability!
So far after 24 hours, I am up 8.7% even with the bug. Had I had the bug fixed, I believe my account would be up double that in one day. However, it will have losers and it does go up in levels, but I trade on nano account, so it is a slow money maker!
Please help!!!
I have the following code:
Inserted Code
//+------------------------------------------------------------------+ //| Safe.mq4 | //| Copyright © 2010 | //+------------------------------------------------------------------+ #property copyright "Copyright © 2010, Dwight Howard" #include <stdlib.mqh> #define acct 0 //if not 0 then will work only on this account number #define expireD 1 #define expireM 1 #define expireY 2090 string Expire_Message = "Your trial is over"; extern int expertId = 99999999; extern int TakeProfit=30; extern int StopLoss=30; extern int BreakevenStop = 200; extern double trailingstart=200; // profit in pips required to enable the trailing stop extern double trailingstop=10; // trailing stop extern double trailingstep=1; // margin allowed to the market to enable the trailing stop extern bool TimeEntry=false; extern string StartTime="0:00"; extern string StopTime="23:59"; extern bool PriceEntry=false; extern double Price=1.3500; extern bool FirstLong=true; extern string LotsProgression="0.01;0.02;0.04;0.08;0.16;0.32;0.64;"; extern bool RestartNewCycle = true; extern int slippage=3; //slippage for market order processing extern int OrderTriesNumber=100000; //to repeat sending orders when you receive an error or requote extern string EAName="Safe"; bool buysig,sellsig,cycleended; int tries,long,short,co,plen,lord,mord,lpos; double Lot,lots[],tlot,lop,lcp,lsl,ltp; double lbid = -1; int counter = 0; double pt,mt; int init() { if(Digits==3 || Digits==5){ pt=Point*10; mt=10; }else{ pt=Point; mt=1; } int i,j,k; string ls; while (true) { j=StringFind(LotsProgression,";",i); if (j>0) { ls=StringSubstr(LotsProgression,i,j-i); i=j+1; k++; ArrayResize(lots,k); lots[k-1]=StrToDouble(ls); } else { ls=StringSubstr(LotsProgression,i); k++; ArrayResize(lots,k); lots[k-1]=StrToDouble(ls); break; } } plen=ArraySize(lots); } void start() { if (Year()*10000+Month()*100+Day()>=expireY*10000+expireM*100+expireD) { Alert("Expire_Message"); double d1; d1=2/d1; return(-1); } if (acct!=0 && AccountNumber()!=acct) { Alert("EA will not work on this account number"); double d; d=2/d; return(-1); } //---- check for history and trading if(Bars<100 || IsTradeAllowed()==false) return; if (lbid == -1) lbid = Bid; co=CalculateCurrentOrders(); if (co > 0) counter = 1; if(trailingstop>0)movetrailingstop(trailingstart,trailingstop); CheckForSignals(); CheckForOpen(); DoBreakEven(BreakevenStop,0); lbid = Bid; } int CalculateCurrentOrders() { int ord; string c; //---- for(int i=0;i<OrdersTotal();i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break; if(OrderSymbol()==Symbol() && OrderMagicNumber()==expertId) { ord++; if (OrderType()==OP_BUY) { mord=1; if (OrderClosePrice()-OrderOpenPrice()>BreakevenStop*pt) tlot=MathAbs(tlot); else tlot=-MathAbs(tlot); } if (OrderType()==OP_SELL) { mord=-1; if (-OrderClosePrice()+OrderOpenPrice()>BreakevenStop*pt) tlot=MathAbs(tlot); else tlot=-MathAbs(tlot); } c=StringSubstr(OrderComment(),0,StringFind(OrderComment(),"_",0)); lpos=StrToInteger(c); return(ord); } } //---- return orders volume return(ord); } double GetLastTrade() { int ord; lord=0; string c; //---- for(int i=OrdersHistoryTotal()-1;i>=0;i--) { if(!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) continue; if(OrderSymbol()==Symbol() && OrderMagicNumber()==expertId) { if (OrderType()==OP_BUY) lord=1; if (OrderType()==OP_SELL) lord=-1; c=StringSubstr(OrderComment(),0,StringFind(OrderComment(),"_",0)); lpos=StrToInteger(c); lop = NormalizeDouble(OrderOpenPrice(), Digits); lcp = NormalizeDouble(OrderClosePrice(), Digits); lsl = NormalizeDouble(OrderStopLoss(), Digits); ltp = NormalizeDouble(OrderTakeProfit(), Digits); if (OrderProfit()>0) return(OrderLots()); else return(-OrderLots()); } } return(0); } bool IsEntryTime() { datetime tm0 = TimeCurrent(); datetime tm1 = StrToTime(TimeToStr(tm0, TIME_DATE) + " " + StartTime); datetime tm2 = StrToTime(TimeToStr(tm0, TIME_DATE) + " " + StopTime); bool isTm = false; if (tm1 <= tm2) isTm = isTm || (tm1 <= tm0 && tm0 < tm2); else isTm = isTm || (tm1 <= tm0 || tm0 < tm2); return (isTm); } void CheckForSignals() { buysig = false; sellsig = false; if (co > 0) return; if (TimeEntry) { bool cond = IsEntryTime(); if (!cond) return; } if (PriceEntry) { cond = ((Bid >= Price && lbid < Price) || (Bid <= Price && lbid > Price)); if (!cond) return; } double lastlot = GetLastTrade(); if (lastlot >= 0) { if (counter > 0) { if (!RestartNewCycle) return; } if (FirstLong) buysig = true; else sellsig = true; lpos = 0; Lot = lots[0]; } else { lpos++; int BE = 0; if (lord > 0 && lcp == lop+BE*pt) lpos--; if (lord < 0 && lcp == lop-BE*pt) lpos--; Lot = lots[lpos]; if (lord > 0) sellsig = true; else if (lord < 0) buysig = true; } } void CheckForOpen() { int res,tr,TP; //---- sell conditions if(sellsig && co==0) { Print("sell open ",Lot," ",lpos); res = OpenAtMarket(OP_SELL,Lot,TakeProfit,lpos); if (res>0) { tlot=Lot; } return; } //---- buy conditions if(buysig && co==0) { Print("buy open ",Lot," ",lpos); res = OpenAtMarket(OP_BUY,Lot,TakeProfit,lpos); if (res>0) { tlot=Lot; } return; } } int OpenAtMarket(int mode,double lot,int TP,int pos) { int res,tr,col; double openprice,sl,tp; tries=0; while (res<=0 && tries<OrderTriesNumber) { tr=0; while (tr<5 && !IsTradeAllowed()) { tr++; Sleep(2000); } RefreshRates(); if (mode==OP_SELL) { openprice=Bid; if (StopLoss>0) sl=openprice+StopLoss*pt; if (TP>0) tp=openprice-TP*pt; col=Red; } else { openprice=Ask; if (StopLoss>0) sl=openprice-StopLoss*pt; if (TP>0) tp=openprice+TP*pt; col=Blue; } res=OrderSend(Symbol(),mode,lot,openprice,slippage,sl,tp,pos+"_"+EAName+"_"+expertId,expertId,0,col); tries++; } Print("market order:: ",Symbol()," ",mode," ",lot," ",openprice," ",sl," ",tp," ",pos+"_"+EAName+"_"+expertId); if (res<=0) Print("error opening order : ",ErrorDescription(GetLastError())); return(res); } void DoBreakEven(int BP, int BE) { bool bres; for (int i = 0; i < OrdersTotal(); i++) { if ( !OrderSelect (i, SELECT_BY_POS) ) continue; if ( OrderSymbol() != Symbol() || OrderMagicNumber() != expertId ) continue; if ( OrderType() == OP_BUY ) { if (Bid<OrderOpenPrice()+BP*pt) continue; if ( OrderOpenPrice()+BE*pt-OrderStopLoss()>pt/10) { //Print(BP," ",BE," bestop"); bres=OrderModify (OrderTicket(), OrderOpenPrice(), OrderOpenPrice()+BE*pt, OrderTakeProfit(), 0, Black); if (!bres) Print("Error Modifying BE BUY order : ",ErrorDescription(GetLastError())); } } if ( OrderType() == OP_SELL ) { if (Ask>OrderOpenPrice()-BP*pt) continue; if ( OrderStopLoss()-(OrderOpenPrice()-BE*pt)>pt/10) { //Print(BP," ",BE," bestop"); bres=OrderModify (OrderTicket(), OrderOpenPrice(), OrderOpenPrice()-BE*pt, OrderTakeProfit(), 0, Gold); if (!bres) Print("Error Modifying BE SELL order : ",ErrorDescription(GetLastError())); } } } return; } void movetrailingstop(double trailingstart,double trailingstop){ RefreshRates(); if(OrdersTotal()>0){ for(int i=OrdersTotal();i>=0;i--){ OrderSelect(i,SELECT_BY_POS,MODE_TRADES); if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==expertId){ if(OrderType()==OP_BUY){ if(NormalizeDouble(Ask,Digits)>NormalizeDouble(OrderOpenPrice()+trailingstart*pt,Digits) && NormalizeDouble(OrderStopLoss(),Digits)<NormalizeDouble(Bid-(trailingstop+trailingstep)*pt,Digits)){ OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-trailingstop*pt,Digits),OrderTakeProfit(),0,Blue); return(0); } } else{ if(NormalizeDouble(Bid,Digits)<NormalizeDouble(OrderOpenPrice()-trailingstart*pt,Digits) && (NormalizeDouble(OrderStopLoss(),Digits)>(NormalizeDouble(Ask+(trailingstop+trailingstep)*pt,Digits))) || (OrderStopLoss()==0)){ OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+trailingstop*pt,Digits),OrderTakeProfit(),0,Red); return(0); } } } } } } /* int FindPos(double ls) { for (int i=0; i<plen; i++) { if (NormalizeDouble(MathAbs(lots[i]-ls),3)<0.001) return(i); } return(-1); } */
THE EA is called POWERSM (in other forum trading systems area)
I have failed to make this profitable until my recent settings and I realized this is the key. Please see my .set file.
It doesn't matter what time frame you run it on, it doesn't care.
It opens an order (blindly) in one direction. If that is a winner, it continues on in that direction until it loses. At which time it is to reverse each time until it wins.
Well, it works that way on the 'longs', but on the shorts even if it wins it reverses to a 'long'?
Can someone help me figure out this as it is beyond my ability!
So far after 24 hours, I am up 8.7% even with the bug. Had I had the bug fixed, I believe my account would be up double that in one day. However, it will have losers and it does go up in levels, but I trade on nano account, so it is a slow money maker!
Please help!!!
Attached File(s)
powersm.set.txt
< 1 KB
|
307 downloads
We are our own best indicator.