# Williama_EA[1].mq4

```//+------------------------------------------------------------------+
//|                                        Williama PriceTrapper.mq4 |
//|                        Based on the great strategie of Williama  |
//|                  Coded by Naufrage, All rights granted to you :) |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Coded by Raphy, All rights granted to you :)"

//---- input parameters
extern int       pips=15; // number of pips between each level
extern double    lots=0.01;
extern int       NbLevels=3; // Number of levels of the pending orders (for each target, buy and sell)
extern int       ProfitTarget=0; //Minimum profit target, in pips. Whatever happen, at least this profit is made (unless we run out of free margin...).

int Magic=17663;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
{
int ticket, cpt, profit, total, BuyGoalProfit, SellGoalProfit;
//----
total=OrdersTotal();
if(total<1) //we can set up a new "price catcher"
{
if(AccountFreeMargin()<(10000*lots))
{
Print("Not enough free margin to begin");
return(0);
}
for(cpt=1;cpt<=NbLevels;cpt++)
{
if(ticket==0)
{
Print("Error opening BUYSTOP order : ",GetLastError());
return(0);
}
if(ticket==0)
{
Print("Error opening SELLSTOP order : ",GetLastError());
return(0);
}
}
} // initial setup done
else
{
cpt=0;
{
cpt++;
}
SellGoal=OrderStopLoss();
// check if pending orders must be canceled
{
for(cpt=0;cpt=SellGoal)
// now we check if profit will be made no matter which goal is reached, and add pending orders if necessary
{
//first, check profit if the BuyGoal is reached
profit=0;
}
}
cpt=1;
while(profitNbLevels) cpt=1;
}
// then, check profit if SellGoal is reached
profit=0;
for(cpt=0;cpt(SellGoal+cpt*pips*Point))
{
if(ticket==0)
{
Print("Error opening SELLSTOP order : ",GetLastError());
return(0);
}
profit+=cpt*pips;
}
cpt++;
if(cpt>NbLevels) cpt=1;
}
}
}
string sComment   = "";
string sep         = "----------------------------------------\n";
string nl         = "\n";
sComment = "Williama EA v.0.1" + nl;
sComment = sComment + "Lots=" + DoubleToStr(lots,2) + nl;
sComment = sComment + "Buy Goal Profit (in pips)=" + BuyGoalProfit + nl + nl;
sComment = sComment + "Sell Goal= " + DoubleToStr(SellGoal,4) + nl;
sComment = sComment + "Sell Goal Profit (in pips)=" + SellGoalProfit + nl + nl;
sComment = sComment + "Pips of each level=" + pips + nl;
sComment = sComment + "Number of levels for each goal: " + NbLevels + nl;