JS_SISTEM_2





//<=====================================================================+||
//                                                      JS_SISTEM.mq4 ||
//                                                             © 2009,||
//                    Ïèøó òîðãîâûå ñèñòåìû    js_sergey@list.ru      ||
//<=====================================================================+||
#define major   1
#define minor   0

//======================================================================||
extern string SS1        =  " ÍÀÑÒÐÎÉÊÈ ÌÌ ";
extern double Minsum     =  100; //-$- îñòàíîâêà ðàáîòû ñîâåòíèêà
extern double Lots       =  0.01;//Ìèíèìàëüíûé ëîò
extern int    StopLoss   =  135;  //StopLoss avto Otstup
extern int    TakeProfit =  400; //Ìàêñèìàëüíûé ïðîôèò
extern bool   MM         =  True;//Óïðàâëåíèå êàïèòàëîì True-âêë 
extern double Risk       =  5;   //Ïðîöåíò ñâîáîäíûõ ñðåäñòâ
extern int    Slippage   =  3;   //Ïðîñêàëüçûâàíèå öåíû
extern int    Volot      =  48;  //Ñêîëüêî áàðîâ ïîêàç âîëîòèëüíîñòü
extern int    Magic      =  12321;
//======================================================================||
extern string SS2        =  " MA ÍÀÑÒÐÎÉÊÈ ";
extern int    Razk       =  28;//EURUSD-28: GBRUSD-39:
extern int    MA_1       =  55;
extern int    MA_2       =  89;
extern int    MA_3       =  144;
//======================================================================||
extern string SS3        =  " OsMA ÍÀÑÒÐÎÉÊÈ ";
extern int    fast       =  13;
extern int    slow       =  55;
extern int    signal     =  21;
//======================================================================||
extern string SS4        =  " RVI ÍÀÑÒÐÎÉÊÈ ";
extern int    RVI_Per    =  55;
extern double RVI_max    =  0.05;
extern double RVI_min    = -0.05;
//======================================================================||
extern string SS5        =  "ÒÐÅÉËÈÍÃ ÒÅÍÈ";
extern bool   Trailing   =  True;
extern int    Tmfrm      =  30; // ïåðèîä, ïî áàðàì êîòîðîãî ñëåäóåò òðàëèòü 
extern int    Bars_n     =  13; // êîë-âî áàðîâ, ïî êîòîðûì ñëåäóåò òðàëèòü
extern int    Indent     =  1;  // îòñòóï îò òåíè áàðà, íà êîòîðîì ðàçìåùàåòñÿ ñòîïëîññ
//======================================================================||
extern string SS6        =  " --- UseSound ---";
extern bool   UseSound   =  True;         // Èñïîëüçîâàòü çâóêîâîé ñèãíàë
extern string Sound_o    =  "ok.wav";     // Íàèìåíîâàíèå çâóêîâîãî ôàéëà
//======================================================================||
#include <stdlib.mqh>
#include <stderror.mqh>
double new_extremum,Rsmin,Rsmax;
int AvgRange;
string comm;
double s1[];
//======================================================================||
int deinit()
{
ObjectDelete("time");
return(0);
}
void start() 
{
if(AccountFreeMargin()<Minsum) // äåíüãè êîí÷èëèñü
{
Print("äåíüãè êîí÷èëèñü = ", AccountFreeMargin());
return(0);  
} 
//========ManiMenedjment=================================================================================================
if(MM){if(Risk<0.1||Risk>100){Comment("Invalid Risk Value.");
return(0);}
else{Lots=MathFloor((AccountFreeMargin()*AccountLeverage()*(Risk/(StopLoss+(Ask-Bid))*100.0)*Point*100.0)/(Ask*MarketInfo(Symbol(),
MODE_LOTSIZE)*MarketInfo(Symbol(),MODE_MINLOT)))*MarketInfo(Symbol(),MODE_MINLOT);}}
if(MM==false){Lots=Lots;}
//=======================================================================================================================
if (Trailing) TrailPositions();  
double OsMA1  = iOsMA(NULL,0,fast,slow,signal,PRICE_CLOSE,0);
double RVI_M  = iRVI(NULL,0,RVI_Per,PRICE_CLOSE,MODE_MAIN);
double RVI_S  = iRVI(NULL,0,RVI_Per,PRICE_CLOSE,MODE_SIGNAL);
double ima_a  = iMA(NULL,0,MA_1,0,3,0,0);
double ima_b  = iMA(NULL,0,MA_2,0,3,0,0);
double ima_c  = iMA(NULL,0,MA_3,0,3,0,0);
int   rash_1  = (ima_a - ima_c)/Point;
int   rash_2  = (ima_c - ima_a)/Point;
//=======================================================================================================================
Rsmax = High[iHighest(NULL, 0, MODE_HIGH, Volot, 0)]; 
Rsmin = Low[iLowest(NULL, 0, MODE_LOW, Volot, 0)];  
AvgRange = (Rsmax - Rsmin)/ Point;
comm = "Âîëîòèëüíîñòü:  " + AvgRange + " ïóíêòîâ" + "\n";
Comment(comm);
//=====×àñû==============================================================================================================
double f;
int m,s,k;
m=Time[0]+Period()*60-CurTime();
f=m/60.0;
s=m%60;
m=(m-m%60)/60;
ObjectDelete("time");
if(ObjectFind("time") != 0)
{
ObjectCreate("time", OBJ_TEXT, 0, Time[0], Close[0]+ 0.0005);
ObjectSetText("time","             "+m+":"+s,8, "Arial", DodgerBlue);
}
else
{
ObjectMove("time", 0, Time[0], Close[0]+0.0005);
}
//=======================================================================================================================
int BuyCnt = 0;
int SellCnt = 0;
int cnt = OrdersTotal();
for (int i=0; i < cnt; i++)
{
if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
if (OrderSymbol() != Symbol()) continue;
if (OrderMagicNumber() != Magic) continue;
int type = OrderType();
if (type == OP_BUY) BuyCnt++;
if (type == OP_SELL) SellCnt++;
}
double price, sl, tp;
//=======================================================================================================================
if (OsMA1>0.0 && RVI_M>RVI_S && RVI_S>=RVI_max && ima_a>ima_b && ima_b>ima_c && rash_1<Razk)
{  
if (BuyCnt > 0) return;
if (CloseOrders(OP_SELL) > 0) return;
price = Ask;
sl = If(StopLoss > 0, price - StopLoss*Point,0);
tp = If(TakeProfit > 0, price + TakeProfit*Point,0);
Buy(Symbol(), GetLots(), price, sl, tp, Magic);
return;
}
//======================================================================================================================
if (OsMA1<0.0 && RVI_M<RVI_S && RVI_S<=RVI_min && ima_a<ima_b && ima_b<ima_c && rash_2<Razk)
{ 
if (SellCnt > 0) return;
if (CloseOrders(OP_BUY) > 0) return;
price = Bid;
sl = If(StopLoss > 0, price + StopLoss*Point,0);
tp = If(TakeProfit > 0, price - TakeProfit*Point,0);
Sell(Symbol(), GetLots(), price, sl, tp, Magic);
return;
}}
//======================================================================================================================
double If(bool cond, double if_true, double if_false)
{
if (cond) return (if_true);
return (if_false);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
double GetLots() 
{
return (Lots);
}
int CloseOrders(int type) 
{  
int cnt = OrdersTotal();
for (int i=cnt-1; i >= 0; i--) 
{
if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
if (OrderSymbol() != Symbol()) continue;
if (OrderMagicNumber() != Magic) continue;
if (OrderType() != type) continue; 
if (type == OP_BUY) 
{
RefreshRates();
CloseOrder(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID));
continue;
}
if (type == OP_SELL) 
{
RefreshRates();
CloseOrder(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK));
continue;
}}
int orders = 0;
cnt = OrdersTotal();
for (i = 0; i < cnt; i++) 
{
if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
if (OrderSymbol() != Symbol()) continue;
if (OrderMagicNumber() != Magic) continue;
if (OrderType() == type) orders++;
}
return (orders); 
}
//======================================================================================================================
void TrailPositions() 
{
int cnt = OrdersTotal();
for (int i=0; i<cnt; i++) 
{
if (!(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))) continue;
if (OrderSymbol() != Symbol()) continue;
if (OrderMagicNumber() != Magic) continue;
//=====ÁËÎÊ==================================TrailingStop===============================================
if (OrderType() == OP_BUY)
{
for(i=1;i<=Bars_n;i++)
{
if (i==1) new_extremum = iLow(NULL,Tmfrm,i);
else 
if (new_extremum>iLow(NULL,Tmfrm,i)) new_extremum = iLow(NULL,Tmfrm,i);
}         
if ((((new_extremum - Bars_n*Point)>OrderStopLoss()) || (OrderStopLoss()==0)) && ((new_extremum - Indent*Point)>OrderOpenPrice()) 
&& (new_extremum - Indent*Point<Bid-MarketInfo(Symbol(),MODE_STOPLEVEL)*Point))
if (!OrderModify(OrderTicket(),OrderOpenPrice(),new_extremum - Indent*Point,OrderTakeProfit(),OrderExpiration()))
return; 
}
//=====ÁËÎÊ=================================TrailingStop=================================================
if (OrderType() == OP_SELL)
{
for(i=1;i<=Bars_n;i++)
{
if (i==1) new_extremum = iHigh(NULL,Tmfrm,i);
else 
if (new_extremum<iHigh(NULL,Tmfrm,i)) new_extremum = iHigh(NULL,Tmfrm,i);
}         
if ((((new_extremum + (Bars_n + MarketInfo(Symbol(),MODE_SPREAD))*Point)<OrderStopLoss()) || (OrderStopLoss()==0)) && 
((new_extremum + (Indent + MarketInfo(Symbol(),MODE_SPREAD))*Point)<OrderOpenPrice()) && 
(new_extremum + (Indent + MarketInfo(Symbol(),MODE_SPREAD))*Point>Ask+MarketInfo(Symbol(),MODE_STOPLEVEL)*Point))
if (!OrderModify(OrderTicket(),OrderOpenPrice(),new_extremum + (Indent + MarketInfo(Symbol(),MODE_SPREAD))*Point,OrderTakeProfit(),OrderExpiration()))
return; 
}}}
//======================================================================================================================
int SleepOk = 2000;
int SleepErr = 6000;
int Buy(string symbol, double lot, double price, double sl, double tp, int magic, string comment="") 
{
int dig = MarketInfo(symbol, MODE_DIGITS);
price = NormalizeDouble(price, dig);
sl = NormalizeDouble(sl, dig);
tp = NormalizeDouble(tp, dig);
    
string _lot = DoubleToStr(lot, 2);
string _price = DoubleToStr(price, dig);
string _sl = DoubleToStr(sl, dig);
string _tp = DoubleToStr(tp, dig);
//======================================================================================================================
int res = OrderSend(symbol, OP_BUY, lot, price, Slippage, sl, tp, comment, magic, 0);
PlaySound(Sound_o);
if (res >= 0)
{
Sleep(SleepOk);
return (res);
} 	
int code = GetLastError();
Print("Error opening BUY order: ", ErrorDescription(code), " (", code, ")");
Sleep(SleepErr);
return (-1);
}
int Sell(string symbol, double lot, double price, double sl, double tp, int magic, string comment="") 
{
int dig = MarketInfo(symbol, MODE_DIGITS);
price = NormalizeDouble(price, dig);
sl = NormalizeDouble(sl, dig);
tp = NormalizeDouble(tp, dig);
string _lot = DoubleToStr(lot, 2);
string _price = DoubleToStr(price, dig);
string _sl = DoubleToStr(sl, dig);
string _tp = DoubleToStr(tp, dig);
//======================================================================================================================
int res = OrderSend(symbol, OP_SELL, lot, price, Slippage, sl, tp, comment, magic, 0);
PlaySound(Sound_o);
if (res >= 0)
{
Sleep(SleepOk);
return (res);
} 	
int code = GetLastError();
Print("Error opening SELL order: ", ErrorDescription(code), " (", code, ")");
Sleep(SleepErr);
return (-1);
}
bool CloseOrder(int ticket, double lot, double price) 
{
if (!OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES)) return(false);
int dig = MarketInfo(OrderSymbol(), MODE_DIGITS);
string _lot = DoubleToStr(lot, 2);
string _price = DoubleToStr(price, dig);
Print("CloseOrder ", ticket, ", ", _lot, ", ", _price, ", ", Slippage);
bool res = OrderClose(ticket, lot, price, Slippage);
if (res)
{
Sleep(SleepOk);
return (res);
} 	
int code = GetLastError();
Print("CloseOrder failed: ", ErrorDescription(code), " (", code, ")");
Sleep(SleepErr);
return (false);
}
//======================================================================================================================



Sample





Analysis



Market Information Used:

Series array that contains the highest prices of each bar
Series array that contains the lowest prices of each bar
Series array that contains open time of each bar
Series array that contains close prices for each bar


Indicator Curves created:


Indicators Used:

Moving Average of Oscillator
Relative Vigor index
Moving average indicator


Custom Indicators Used:

Order Management characteristics:
Checks for the total of open orders
It can change open orders parameters, due to possible stepping strategy
It automatically opens orders when conditions are reached
It Closes Orders by itself

Other Features:


It plays sound alerts

BackTest : EURUSD on H1

From 2009-08-01 to 2009-10-01 Profit Factor:0.00 Total Net Profit:0.00

BackTest : EURUSD on H1

From 2009-12-01 to 2010-01-17 Profit Factor:0.00 Total Net Profit:0.00

BackTest : EURUSD on H1

From 2010-04-01 to 2010-04-30 Profit Factor:0.00 Total Net Profit:0.00

BackTest : EURUSD on H1

From 2010-05-01 to 2010-05-31 Profit Factor:0.00 Total Net Profit:0.00

BackTest : EURUSD on H1

From 2010-06-01 to 2010-06-30 Profit Factor:0.00 Total Net Profit:0.00

BackTest : GBPUSD on H1

From 2010-01-01 to 2010-02-27 Profit Factor:0.00 Total Net Profit:0.00

BackTest : USDCAD on H1

From 2009-12-01 to 2010-01-01 Profit Factor:0.00 Total Net Profit:0.00

BackTest : USDCHF on H1

From 2009-12-01 to 2010-01-01 Profit Factor:0.00 Total Net Profit:0.00

BackTest : USDJPY on H1

From 2009-11-01 to 2009-11-30 Profit Factor:0.00 Total Net Profit:0.00

Request Backtest for JS_SISTEM_2


From : (yyyy/mm/dd) To: (yyyy/mm/dd)

Pair: Period: