Please Help with Price reconition

 

Hello Everybody,

I am new to this forum...and I would say I have the basics of writing an EA.

I have 95% completed an EA but I have run into a situation that I cannot seem to resolve.

The EA uses a simple Moving average to dictate when trades are generated.

This moving average has to have certian things in accordance to prices that end in either 00 or 50.

Is there a "double" code that I can use so the EA will pick up all price lines that end in 00 or 50

I write the codes as followes:

double Sma1 = iSma(code,code,code...........);

So is there a way I can make it see the price lines like:

double Price00 = ????(code,code,code...all prices that end w/ 00);

double Price50 = ????(code,code,code...all prices that end w/ 50);

Any assitance is greatly appericated.

 

Try

if(MathMod(price/Point, 100) == 0) // found 00

if(MathMod(price/Point, 50) == 0 && MathMod(price/Point, 100) != 0) // found 50

or

int modulus00, modulus50;

modulus00 = MathMod(price/Point, 100);

modulus50 = MathMod(price/Point, 50);

if(modulus00 == 0) // found 00

if(modulus50 == 0 && modulus00 != 0) // found 50

 

Thank you very much, giving it a try...still kinda stuck.

Let me show you what I am working on......

int start()
{
int cnt, ticket, total, modulus00, modulus50;
// initial data checks
// it is important to make sure that the expert works with a normal
// chart and the user did not make any mistakes setting external
// variables (Lots, StopLoss, TakeProfit,
// TrailingStop) in our case, we check TakeProfit
// on a chart of less than 100 bars
if(Bars<100)
{
Print("bars less than 100");
return(0);
}
// to simplify the coding and speed up access
// data are put into internal variables

double ShortEma1=iMA(NULL,0,1,0,1,0,1);
double ShortEma2=iMA(NULL,0,1,0,1,0,2);
double TakeProfit = 9999;
double StopLoss = 9999;
double TrailingStop = 0;
double Equity = AccountEquity();
double Balance = AccountBalance();
double price = PRICE_CLOSE;
modulus00 = MathMod(price/Point, 100);
modulus50 = MathMod(price/Point, 50);


total=OrdersTotal();
if(total<MaxOrders)
{
// no opened orders identified
{
if(CheckEntryTime==iTime(NULL,TimeFrame,0)) return(0); else CheckEntryTime = iTime(NULL,TimeFrame,0);
}
if(AccountFreeMargin()<(1*Lots))
{
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}
// Lets Buy !!!!!
if(ShortEma2<modulus00 && ShortEma1>modulus00 ||
ShortEma2<modulus50 && ShortEma1>modulus50)
{
ticket=OrderSend(Symbol(),OP_BUY,Lots+(Lot_Increase*total),Ask,3,Ask-(StopLoss*Point),Ask+TakeProfit*Point,"Good Luck",MagicNumber,0,Green);
PlaySound(SoundAlert);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening BUY order : ",GetLastError());
return(0);
}

At this point in the code....it SHOULD, OR I WANT IT TO, open a buy position every time we have the ShortEMA move from below eithe the 00 or the 50 price lines..........

Please Assist.

 

modulus50 will have values from 0 to 49

modulus00 will have values from 0 to 99

Plug in those numbers and look at your code again.

 

phy,

Thank you very much for your help on this.

I have manually traded my system and it produces profits....but takes a lot of attention...which is why I am working on the EA.

I am sorry, but I simply cannot grasp what you mean by plugging in those figures...where would I plug them in at ?

Also I recieved an error that says the "price" value is not defined in the Modulus...I assumed it would be PRICE_CLOSE so I used that....

How would you write it so the EA understand that it is to open an order when the SMA moves from below to above either the 00 or the 50 price lines ?

 

You have variable names, "plug in the value" means to assign a value (maybe mentally) to your variable and read the code.

Example:

// Lets Buy !!!!!
if(ShortEma2<modulus00 && ShortEma1>modulus00 || ShortEma2<modulus50 && ShortEma1>modulus50)
Lets say price = 1.3557

modulus50 is 7 in this case.

modulus00 is 57 in this case.

if(ShortEma2< 57 && ShortEma1> 57 || ShortEma2 < 7 && ShortEma1 > 7)

Your eam values will be near 1.3557, so when will the "if" be true?

---

rethink your logic

 

Rethinking my logic....................................................ok, that was not fun :)

I understand what you are saying, using that formula, there is never a true statment because the price will always be different than 7 or 57 (as given in your example).

I believe that making the equation simpler will be the way to go. So, I removed the modulus codes, and converted the "double price = Price_Close" to an exact number for testing purposes. Doing this worked of course, as orders were opened whenever the SMA crossed the inserted Price amount.

Where I ran into the new road block is that I would like it to open orders every time the SMA crosses a price line that ends in 50 or 00. I am willing to manually enter these, but if I write the line as follows:

double price = 1.0000 || 1.0050 || 1.0100 || 1.0150 || ect............

then the EA does not open any orders at all, Could you suggest a way to write this line so the "price" variable represents all lines that end in 50 or 00 ?

 

int price = Bid/Point;

if(MathMod(price, 50) == 0){

// found 00 or 50

OrderSend();

}

Reason: