How to code? - page 117

 
mystified:
I have added levels to HMA:

#property indicator_separate_window

#property indicator_buffers 2

#property indicator_color1 Black

#property indicator_color2 Red

#property indicator_width1 2

#property indicator_minimum 0

#property indicator_maximum 100

#property indicator_level1 80

#property indicator_level2 60

#property indicator_level3 40

#property indicator_level4 20

#property indicator_levelcolor DarkSlateGray

But the indicator doesnt appear on a seperate window properly.Any help much appreciated.

Because the indicator is forced bounded:

Remove this two lines:

#property indicator_minimum 0

#property indicator_maximum 100

Levels only works fine on bounded indicators but to do a bounded indicator the calculation must include the limits.

Example: RSI = 100-(100/(1+U/D))

We know by that formula that the indicator will move between 0-100 and because that we could include 70-30 levels without fear to they would disappear.

Another example is MACD = EMA(CLOSE, 12)-EMA(CLOSE, 26)).

We set a level on M5 and when we move to H1 most probable is the level has gone.

So, we take the same formula and we make some changes MACD = (EMA(CLOSE, 12)-EMA(CLOSE, 26))/EMA(CLOSE, 26). And now we have a percent indicator. Is not bounded but we have less probabilities to lost our levels.

 

Thanks Linuxer.

 
i have created a really simple EA. and a system which i use in atleast 3 Timeframe..May problem it doesn't stop opening and i don't want to have 3 EA and 3 chart for one pair.

i need a code that would only do one order for buy and for sell per bar per TF and still open if it is on a different bar. i can have buy and sell and the same bar.

Sometimes i have 3 signal in 3 different TF. i want to take all order but i want only one order per TF and i can still take another order in another TF if it is still open but in a different bar.

example:

1 signal in 4h

1 signal in 1h but it falls in bar for 4h

1 signal in 30 min but only one bar for 1h and 4h.

3 signal will be open.

i am ok with using magic number as means of filter.

can someone help me? thank you very much.

so far this is what i thought:

for 30 mins

if (magicnumber == 123)

{

if (iTime(OrderOpenTime()) != iTime(Symbol(),PERIOD_M30,0))

{//my order code}

}

i don't have MT4 but i know somethings is not right in the logic or code. So guys please help me.

also i think we have similar problem with matrixebiz

Can anyone help me please?

 
mystified:
Thanks Linuxer.

This is just the example (because now you have the Oscillator HMA ) from previous post, still it's MACD but calculated on a different way.

 
 

How to start trading on the opening candle in D1 ??

is there anyone know the code to ask the EA start open trade when the new bar start in D1 time frame ??

here is the logic:

in D1 TF, when the new candle (it's mean a new day) is start then EA will open 2 position, BUY and SELL with TP=10 pips for each position.

When the candle closed then EA close all position and start opening position again for the new candle.

very simple rule, but still I cann't find the code for this simple rule....

I'm realy new in MQL4 coding and already search and read many source and forum to learn more about MQL4 coding, but cann't find what I'm need.

Thanks before...

 

here is my code.... please help me to fix it

I tried to code what I have ask before, here is the sample EA code:

int start()

{

LastPrice=0;

LastProfit=0;

LastTicket=0;

LastLots=Lots;

Profit=0;

ProfitPip=0;

PairOrder=0;

OrdersOpened = 0;

PreviousOrders = OrdersOpened;

double Spread = MarketInfo(Symbol(),MODE_SPREAD);

PipValue=MarketInfo(Symbol(),MODE_TICKVALUE);

ArrayCopyRates(rates, Symbol(), PERIOD_D1);

if(DayOfWeek()==0 || DayOfWeek()==6)

{

//no trade on holiday;

return(0);

}

else

{

if (newbar()==Period())

{

for (int cnt = OrdersTotal() - 1; cnt >= 0; cnt --)

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)

{

OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), Slippage, Color1);

}

}

OpenBuy();

OpenSell();

}

}

}

int newbar()

{

double g;

int m,s,k;

m=Time[0]+Period()*60-TimeCurrent();

g=m/60.0;

s=m%60;

m=(m-m%60)/60;

return(m);

}

void OpenBuy()

{

double ldLot, ldStop, ldTake;

string lsComm;

ldLot = GetSizeLot();

ldStop = Ask-Point*StopLoss;

ldTake = NormalizeDouble(GetTakeProfitBuy(),Digits);

OrderSend(Symbol(),OP_BUY,ldLot,NormalizeDouble(Ask,Digits),Slippage,ldStop,ldTake,"BUY",Magic,0,Color1);

}

void OpenSell()

{

double ldLot, ldStop, ldTake;

string lsComm;

ldLot = GetSizeLot();

ldStop = Bid+Point*StopLoss;

ldTake = NormalizeDouble(GetTakeProfitSell(),Digits);

OrderSend(Symbol(),OP_SELL,ldLot,NormalizeDouble(Bid,Digits),Slippage,ldStop,ldTake,"SELL",Magic,0,Color1);

}

double GetSizeLot()

{

return(Lots);

}

double GetTakeProfitBuy()

{

return(Ask+TakeProfit*Point);

}

double GetTakeProfitSell()

{

return(Bid-TakeProfit*Point);

}

Last night I uploaded to my vps, but this morning I check it up but my sample EA doesn't open any trade, can someone here help me to fix my sample EA here ??

btw, I attached it here too

 

Alerts that last longer

hi i am newbie trying to understand ins and outs of this and any help will be appreciated!!

my current indicator has the following code for generating alerts, but this alert lasts for only one beep, is there any way i can make it to beep for 30 or 60 sec or atleast bit longer than 1 beep

if (setalert == 1 && shift == 0) {

Alert(Symbol(), " ", period, " ", pattern);

setalert = 0;

}

Thanks

 

Re Coding to metatrader (Klinger Volume Oscillator)

The Klinger Oscillator (KO) was developed by Stephen J. Klinger. Learning from prior research on volume by such well-known technicians as Joseph Granville, Larry Williams, and Marc Chaikin, Mr. Klinger set out to develop a volume-based indicator to help in both short- and long-term analysis.

The KO was developed with two seemingly opposite goals in mind: to be sensitive enough to signal short-term tops and bottoms, yet accurate enough to reflect the long-term flow of money into and out of a security.

The KO is based on the following tenets:

* Price range (i.e. High - Low) is a measure of movement and volume is the force behind the movement. The sum of High + Low + Close defines a trend. Accumulation occurs when today's sum is greater than the previous day's. Conversely, distribution occurs when today's sum is less than the previous day's. When the sums are equal, the existing trend is maintained.

* Volume produces continuous intra-day changes in price reflecting buying and selling pressure. The KO quantifies the difference between the number of shares being accumulated and distributed each day as "volume force". A strong, rising volume force should accompany an uptrend and then gradually contract over time during the latter stages of the uptrend and the early stages of the following downtrend. This should be followed by a rising volume force reflecting some accumulation before a bottom develops.

* By converting the volume force into an oscillator representing the difference between a 34-period and 55-period exponential moving average with a 13-period trigger, the force of volume into and out of a security can easily be tracked. Comparing this force to price action can help identify divergences at tops and bottoms.

Interpretation

Mr. Klinger recommends the following guidelines for using the KO:

1. The most reliable signals occur in the direction of the prevailing trend. Strict stop guidelines (i.e., failure to penetrate the zero line or a violation of the trigger line) should remain in force.

2. The most important signal occurs when the KO diverges with the underlying price action, especially on new highs or new lows in overbought/oversold territory. For example, when a stock makes a new high or low for a cycle and the KO fails to confirm this, the trend may be losing momentum and nearing completion.

3. If the price is in an uptrend (i.e., above an 89-day exponential moving average), buy when the KO drops to unusually low levels below zero, turns up, and crosses its trigger line. If the price is in a downtrend (i.e., below an 89-day exponential moving average), sell when the KO rises to unusually high levels above zero, turns down, and crosses its trigger line.

While the KO works well for timing trades in the direction of the trend, it is less effective against the trend. This can create problems for the trader trying to "scalp" a trade against the prevailing trend. However, when the KO is used in conjunction with other technical indicators, better results can be achieved. William's %R is recommended for confirming an overbought/oversold price condition and Gerald Appel's MACD is recommended for confirming the short-term direction of price.

Tip

Stephen Klinger suggests the following formula for viewing the cumulative flow of money into and out of a security:

cum(kvo())

Plot a 13-period moving average of the formula as a trigger line for entering buy and sell trades.

source codenya untuk trade station

Type: Function, Name: VForce

Vars: TSum(0), Trend(0), DM(0), CM(0);

TSum = High + Low + Close;

IF TSum > TSum[1] Then

Trend = 1

Else

Trend = -1;

IF Trend = Trend[1] Then

CM = CM + Range

Else

CM = Range + Range[1];

IF CM 0 Then

VForce = Volume * AbsValue(2 * (DM/CM) -1) * Trend * 100;

Type: Function, Name: KVO

Inputs:

FastX(Numeric),

SlowX(Numeric); Vars:

FXAvg(0),

SXAvg(0);

FXAvg = XAverage(VForce, FastX);

SXAvg = XAverage(VForce, SlowX);

KVO = FXAvg - SXAvg;

Type: Indicator, Name: Klinger Volume Oscillator

Inputs:

FastX(34),

SlowX(55),

TrigLen(13),

Smooth(1);

Vars:

Trigger(0);Trigger = XAverage(KVO(FastX, SlowX), TrigLen);IF Smooth <= 1 Then Begin

Plot1(KVO(FastX, SlowX), "KVO");

Plot2(Trigger, "KVO Trigger");

End Else BeginPlot1(Summation(KVO(FastX, SlowX), Smooth), "KVO");

Plot2(Summation(Trigger, Smooth), "KVO Trigger");

End;

Plot3(0, "Zero");

IF Plot1 Crosses Above Plot2 OR Plot1 Crosses Below Plot2 OR

Plot2 Crosses Above Plot3 OR Plot2 Crosses Below Plot3 Then

Alert = True;

someone would like to help me to convert this coding into Mql4?

thks