How to code? - page 43

 
jimven:
Flytox: I cannot find such code in my copy of TrendStrength.

It's TrendStrength v2.2

 

Custom Pricemode

Does anyone know how to make a custom pricemode ? I am using the following alert to signal when the price (extern int PriceMode = 6; //(high+low+close+close)/4) crosses a MA. I would like to make this custom by adding an offset, say 1 or 2 %. Is this possible ? Something like:

extern int PriceMode = ((high+low+close+close)/4) * 1.01

----------------------------------------------------

#property indicator_chart_window

extern int MA1.period =5; //Period 5

extern int MA1.shift=0;

extern int MA1.method=2; //SMMA

extern int lMA1.price=2; //MA set to candle high

extern int sMA1.price=3; //MA set to candle low

extern int PriceMode = 6; //(high+low+close+close)/4

int cBar,pBarLong,pBarShort;

int start()

{

cBar = Time[0];

if(CheckMACross(1)== 1 && cBar!=pBarLong ) {EmailAlert(1); pBarLong=cBar;}

else

if(CheckMACross(2)==-1 && cBar!=pBarShort) {EmailAlert(2); pBarShort=cBar;}

return(0);

}

int CheckMACross(int mode)

{

if(mode==1) int price = lMA1.price;

else

if(mode==2) price = sMA1.price;

double price1 = iMA(Symbol(),0,1,0,1,PriceMode,1);

double ma1 = iMA(Symbol(),0,MA1.period,MA1.shift,MA1.method, price,1);

double price0 = iMA(Symbol(),0,1,0,1,PriceMode,0);

double ma0 = iMA(Symbol(),0,MA1.period,MA1.shift,MA1.method, price,0);

if(ma1 > price1 && ma0 <= price0) return( 1);

else

if(ma1 = price0) return(-1);

else

return(0);

}

{

if(mode == 1) SendMail("Signal for LONG",Symbol()+" Go Long"); //SendMail

else

if(mode == 2) SendMail("Signal for SHORT",Symbol()+" Go Short");//SendMail

}

int lastBAlert = 0;

int lastSAlert = 0;

void EmailAlert(int mode)

{

if(mode == 2 && lastSAlert < Time[0] )

{

SendMail("Go Short 1",Symbol()+" Go Short 1"); //SendMail

lastSAlert = Time[0];

}

}

 
vonokpasah:
I am appealing to the experts out there to please come to my aid i need some to help me buld an EXPERT ADVISER META 4 TRADER for me i would be greatfull if my request is granted.

Millions of ways to build an expert, what way were you thinking?

 

source code help!

Hello all

I have an EA and i want to add an input to it

If take profit >= :xx , buy :xx lot

extern int Deltaopen1 =100;

I wrote;

if (type == OP_BUY)

{

if (M2.BuyCnt == 0 && OrderTakeProfit() > OrderOpenPrice() + Deltaopen1*point)

{

Buy(Symbol(), GetLots2(), Ask, 0, 0, Magic2);

return;

}

}

if (type == OP_SELL)

{

if (M2.SellCnt == 0 && OrderTakeProfit() <= OrderOpenPrice() - Deltaopen1*point)

{

Sell(Symbol(), GetLots2(), Bid, 0, 0, Magic2);

return;

}

}

}

But it does not work,

I appreciate any help.

Thank you

 

Need a little help refining this EA

I have this ea which is a modified version of the "GAPS EA" found elsewhere on this forum.

Anyway, attached is a copy of the code.

#property link ""

//---- input parameters

extern int min_gapsize = 1;

extern double lotsize_gap = 5;

extern int MagicNumber = 10;

//----

datetime order_time = 0;

//+------------------------------------------------------------------+

//| expert initialization function |

//+------------------------------------------------------------------+

int init()

{

//----

return(0);

}

//+------------------------------------------------------------------+

//| expert deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

//----

return(0);

}

//+------------------------------------------------------------------+

//| expert start function |

//+------------------------------------------------------------------+

int start()

{

/*

Thing to be done in future in this program to make it more efficient

and more powerful:

1. Make the dicission of the quantity of lots used according to

the scillators;

2. This program will catch the gaps.

Things to ware of:

1. the spread;

2. excuting the order not on the gap ends a little bit less.

*/

// Defining the variables to decide.

Print("order time", order_time);

double current_openprice = iOpen(Symbol(), 0, 0);

double previous_highprice = iHigh(Symbol(), 0, 1);

double previous_lowprice = iLow(Symbol(), 0, 1);

double point_gap = MarketInfo(Symbol(), MODE_POINT);

int spread_gap = MarketInfo(Symbol(), MODE_SPREAD)+1;

datetime current_time = iTime(Symbol(), 0, 0);

// catching the gap on sell upper gap

if(current_openprice > previous_highprice + (min_gapsize + spread_gap)*point_gap &&

current_time != order_time)

{

int ticket = OrderSend(Symbol(), OP_SELL, lotsize_gap, Bid, 0, 0,

previous_highprice + spread_gap,

"Gapped Up Sell " + Symbol()+ " " +Period()+ "", MagicNumber, 0, Red);

order_time = iTime(Symbol(), 0, 0);

Print("I am inside (sell) :-)", order_time);

//----

if(ticket < 0)

{

Print("OrderSend failed with error #", GetLastError());

}

}

//catching the gap on buy down gap

if(current_openprice < previous_lowprice - (min_gapsize + spread_gap)*point_gap &&

current_time != order_time)

{

ticket = OrderSend(Symbol(), OP_BUY, lotsize_gap, Ask, 0, 0,

previous_lowprice - spread_gap,

"Gapped Down Buy " + Symbol()+ " " +Period()+ "", MagicNumber, 0, Green);

order_time = iTime(Symbol(), 0, 0);

Print("I am inside (buy) :-)", order_time);

if(ticket < 0)

{

Print("OrderSend failed with error #", GetLastError());

}

}

//----

return(0);

}

//+------------------------------------------------------------------+

Whenever I put this into the strategy tester, it doesn't open trades. A quick peek at the journal tells me that there were plenty of order times made. What did I do wrong?

 

Help: Basic Histogram Question

This is probably really easy and I'm looking past something, but I'm out of resources and can't find an answer.

All I'm trying to do is recall the value of the previously drawn histogram bar.

Any ideas?

I.e. Close[1] shows the last closed bar on the chart.....

So what would show the last drawn histogram bar on this separate window indicator?

Thanks for any advice in advance.

-dharsant

 
dharsant:
This is probably really easy and I'm looking past something, but I'm out of resources and can't find an answer.

All I'm trying to do is recall the value of the previously drawn histogram bar.

Any ideas?

I.e. Close[1] shows the last closed bar on the chart.....

So what would show the last drawn histogram bar on this separate window indicator?

Thanks for any advice in advance.

-dharsant

Which indicator are you calling? Just set the shift to call the previous bar.

Example, for a current bar moving average:

iMA(NULL,0,13,8,MODE_SMMA,PRICE_MEDIAN,0);

For a previous bar moving average:

iMA(NULL,0,13,8,MODE_SMMA,PRICE_MEDIAN,1);

The last parameter when calling an indicator signifies how many bars from current will be read.

Hope this is what you were looking for.

 

Coding Help Needed Please

I am trying to use a couple of different indicators in an ea but can't seem to work out how to implement them in to the system. What part of the indicator do I use to say buy or sell. How do I get Slope Direction Line into part of an EA.

Cheers

Beno

Files:
 

I have probably not explained myself quite right.

I am trying to find out what I need to put into iCustom this is what I have done below.

double SDL=iCustom(NULL,0,"Slope Direction Line",period,method,price)

And what I need to do to generate buy and sell signal from Slope Direction Line Indicator for my EA. Below is what I have done so far, it compiles but no positions are being generated.

bool Long = TML && SDL && HeikenAshiOpen < HeikenAshiClose && hasOpen < hasClose;

bool Short = TMS && SDL && HeikenAshiOpen > HeikenAshiClose && hasOpen > hasClose;

Any help would be great

Cheers

Beno

 

Firstly the iCustom call needs two additional arguments at the end, namely which of the indicator buffers to read from, and which index to read at.

Secondly, "SDL" is a double number, so to just put "SDL" as a condition shows some confusion; possibly it compiles as "SDL != 0", and possibly that's what is meant.