CodeGenius v3.0 “Monte Carlo Forex”: The Most Sophisticated Robot I Ever Designed is to be released soon…
Complete with Semi-Martingale and Martingale that based on Higher Dimensions of Topological Spaces and Methodology that implements Chaos Theory, Turbulence and Markov Chain on Monte Carlo Algorithm in FOREX.
//+——————————————————————————–+
//| Neural Kohonen-Hebbian Self-Learning Networks |
//| Copyright © 2011, Mohamad Izaham Bin Mohamed Yatim |
//| http://www.omnifarm.biz |
//| COMPLETE VERSION 2.66 FINAL WITH CORRECT FUNCTIONS |
//+——————————————————————————–+
#property copyright “Copyright © 2011, Mohamad Izaham Bin Mohamed Yatim”
#property link “http://www.omnifarm.biz”
#include <stdlib.mqh>
#include <WinUser32.mqh>
// exported variables
extern double Amount32 = 0;
extern double BuyLots46 = 0.1;
extern double Amount51 = 0;
extern double SellLots40 = 0.1;
// local variables
double PipValue=1; // this variable is here to support 5-digit brokers
bool Terminated = false;
string LF = “\n”; // use this in custom or utility blocks where you need line feeds
int NDigits = 4; // used mostly for NormalizeDouble in Flex type blocks
int ObjCount = 0; // count of all objects created on the chart, allows creation of objects with unique names
int current = 0;
int Count19 = 0;
int init()
{
NDigits = Digits;
if (true) ObjectsDeleteAll(); // clear the chart
Comment(“”); // clear the chart
}
// Expert start
int start()
{
if (Bars < 10)
{
Comment(“Not enough bars”);
return (0);
}
if (Terminated == true)
{
Comment(“EA Terminated.”);
return (0);
}
OnEveryTick53();
}
//————————————————————–
// Put Your Mathematical Functions In Here!
//————————————————————–
//
//
//
//
//————————————————————–
void OnEveryTick53()
{
if (true == false && true) PipValue = 10;
if (true && (NDigits == 3 || NDigits == 5)) PipValue = 10;
PrintToLog25();
IfDemo26();
PrintInfoToChart19();
IfOrderExists34();
IfOrderDoesNotExist52();
IfOrderExists49();
IfTesting28();
IfOrderDoesNotExist42();
}
void PrintToLog25()
{
Print(“I am Thinking, Honey…”);
}
void IfDemo26()
{
if (IsDemo())
{
Terminate27();
}
}
void Terminate27()
{
Print(“EA Terminated.”);
Terminated = true;
}
void PrintInfoToChart19()
{
string temp = “Some Text\nExecuted : ” + Count19 + “\n”
+ “Spread: ” + DoubleToStr(MarketInfo(Symbol(), MODE_SPREAD)/PipValue, 2)+ “\n”
+ “————————————————\n”
+ “ACCOUNT INFORMATION:\n”
+ “\n”
+ “Account Name: ” + AccountName()+ “\n”
+ “Account Leverage: ” + DoubleToStr(AccountLeverage(), 0)+ “\n”
+ “Account Balance: ” + DoubleToStr(AccountBalance(), 2)+ “\n”
+ “Account Equity: ” + DoubleToStr(AccountEquity(), 2)+ “\n”
+ “Free Margin: ” + DoubleToStr(AccountFreeMargin(), 2)+ “\n”
+ “Used Margin: ” + DoubleToStr(AccountMargin(), 2)+ “\n”
+ “————————————————\n”;
Comment(temp);
Count19++;
}
void IfOrderExists34()
{
bool exists = false;
for (int i=OrdersTotal()-1; i >= 0; i–)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
{
exists = true;
}
}
else
{
Print(“OrderSelect() error – “, ErrorDescription(GetLastError()));
}
if (exists)
{
TechnicalAnalysis3xOr33();
CloseOrderIf32();
}
}
void TechnicalAnalysis3xOr33()
{
if ((0 > 0) || (0 > 0) || (0 > 0))
{
BuyOrderModifyFlex31();
}
}
void BuyOrderModifyFlex31()
{
for (int i=OrdersTotal()-1; i >= 0; i–)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
{
double SL = NormalizeDouble(Low[1], NDigits);
double TP = NormalizeDouble(High[1], NDigits);
bool ret = OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0, White);
if (ret == false)
Print(“OrderModify() error – “, ErrorDescription(GetLastError()));
}
}
PrintToLog30();
}
void PrintToLog30()
{
Print(“Buy Order Modify Flexy”);
}
void CloseOrderIf32()
{
int orderstotal = OrdersTotal();
int orders = 0;
int ordticket[30][2];
for (int i = 0; i < orderstotal; i++)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if (OrderType() != OP_BUY || OrderSymbol() != Symbol() || OrderMagicNumber() != 1)
{
continue;
}
if (OrderProfit() > Amount32)
{
ordticket[orders][0] = OrderOpenTime();
ordticket[orders][1] = OrderTicket();
orders++;
}
}
if (orders > 1)
{
ArrayResize(ordticket,orders);
ArraySort(ordticket);
}
for (i = 0; i < orders; i++)
{
if (OrderSelect(ordticket[i][1], SELECT_BY_TICKET) == true)
{
bool ret = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 4, Red);
if (ret == false)
Print(“OrderClose() error – “, ErrorDescription(GetLastError()));
}
}
PrintToLog29();
}
void PrintToLog29()
{
Print(“Buy Order Close If”);
}
void IfOrderDoesNotExist52()
{
bool exists = false;
for (int i=OrdersTotal()-1; i >= 0; i–)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
{
exists = true;
}
}
else
{
Print(“OrderSelect() error – “, ErrorDescription(GetLastError()));
}
if (exists == false)
{
TechnicalAnalysis3xOr48();
}
}
void TechnicalAnalysis3xOr48()
{
if ((0 > 0) || (0 > 0) || (0 > 0))
{
BuyOrderFlex46();
}
}
void BuyOrderFlex46()
{
double SL = NormalizeDouble(Low[1], NDigits);
if (Low[1] == 0) SL = 0;
double TP = NormalizeDouble(High[1], NDigits);
if (High[1] == 0) TP = 0;
int ticket = -1;
if (true)
ticket = OrderSend(Symbol(), OP_BUY, BuyLots46, Ask, 4, 0, 0, “My Expert”, 1, 0, Blue);
else
ticket = OrderSend(Symbol(), OP_BUY, BuyLots46, Ask, 4, SL, TP, “My Expert”, 1, 0, Blue);
if (ticket > -1)
{
if (true)
{
OrderSelect(ticket, SELECT_BY_TICKET);
bool ret = OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0, Blue);
if (ret == false)
Print(“OrderModify() error – “, ErrorDescription(GetLastError()));
}
PrintToLog47();
}
else
{
Print(“OrderSend() error – “, ErrorDescription(GetLastError()));
}
}
void PrintToLog47()
{
Print(“Buy Order Initiated”);
}
void IfOrderExists49()
{
bool exists = false;
for (int i=OrdersTotal()-1; i >= 0; i–)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
{
exists = true;
}
}
else
{
Print(“OrderSelect() error – “, ErrorDescription(GetLastError()));
}
if (exists)
{
TechnicalAnalysis3xOr50();
CloseOrderIf51();
}
}
void TechnicalAnalysis3xOr50()
{
if ((0 > 0) || (0 > 0) || (0 > 0))
{
SellOrderModifyFlex45();
}
}
void SellOrderModifyFlex45()
{
for (int i=OrdersTotal()-1; i >= 0; i–)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
{
double SL = NormalizeDouble(High[1], NDigits);
double TP = NormalizeDouble(Low[1], NDigits);
bool ret = OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0, White);
if (ret == false)
Print(“OrderModify() error – “, ErrorDescription(GetLastError()));
}
}
PrintToLog43();
}
void PrintToLog43()
{
Print(“Sell Order Modify Flexy”);
}
void CloseOrderIf51()
{
int orderstotal = OrdersTotal();
int orders = 0;
int ordticket[30][2];
for (int i = 0; i < orderstotal; i++)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if (OrderType() != OP_SELL || OrderSymbol() != Symbol() || OrderMagicNumber() != 1)
{
continue;
}
if (OrderProfit() > Amount51)
{
ordticket[orders][0] = OrderOpenTime();
ordticket[orders][1] = OrderTicket();
orders++;
}
}
if (orders > 1)
{
ArrayResize(ordticket,orders);
ArraySort(ordticket);
}
for (i = 0; i < orders; i++)
{
if (OrderSelect(ordticket[i][1], SELECT_BY_TICKET) == true)
{
bool ret = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 4, Red);
if (ret == false)
Print(“OrderClose() error – “, ErrorDescription(GetLastError()));
}
}
PrintToLog44();
}
void PrintToLog44()
{
Print(“Sell Order Close If”);
}
void IfTesting28()
{
if (IsTesting())
{
Terminate27();
}
}
void IfOrderDoesNotExist42()
{
bool exists = false;
for (int i=OrdersTotal()-1; i >= 0; i–)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
{
exists = true;
}
}
else
{
Print(“OrderSelect() error – “, ErrorDescription(GetLastError()));
}
if (exists == false)
{
TechnicalAnalysis3xOr41();
}
}
void TechnicalAnalysis3xOr41()
{
if ((0 > 0) || (0 > 0) || (0 > 0))
{
SellOrderFlex40();
}
}
void SellOrderFlex40()
{
double SL = NormalizeDouble(High[1], NDigits);
if (High[1] == 0) SL = 0;
double TP = NormalizeDouble(Low[1], NDigits);
if (Low[1] == 0) TP = 0;
int ticket = -1;
if (true)
ticket = OrderSend(Symbol(), OP_SELL, SellLots40, Bid, 4, 0, 0, “My Expert”, 1, 0, Red);
else
ticket = OrderSend(Symbol(), OP_SELL, SellLots40, Bid, 4, SL, TP, “My Expert”, 1, 0, Red);
if (ticket > -1)
{
if (true)
{
OrderSelect(ticket, SELECT_BY_TICKET);
bool ret = OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0, Red);
if (ret == false)
Print(“OrderModify() error – “, ErrorDescription(GetLastError()));
}
PrintToLog39();
}
else
{
Print(“OrderSend() error – “, ErrorDescription(GetLastError()));
}
}
void PrintToLog39()
{
Print(“Sell Order Flexy Initiated “);
}
int deinit()
{
if (true) ObjectsDeleteAll();
}












Recent Comments