Simple Coding Help - No Promise.

manojborle

Well-Known Member
can anyone please post the code of on balance volume (OBV) and money flow index (MFI)?
these are the default indicators of AB!
Plot( OBV(), _DEFAULT_NAME(), ParamColor("Color", colorCycle ), ParamStyle("Style") );

periods = Param( "Periods", 14, 2, 200, 1 );
Plot( MFI(periods), _DEFAULT_NAME(), ParamColor("Color", colorCycle ), ParamStyle("Style") );

Is this you are looking for ?
 

xsis

Active Member
no manoj! this code is available in AB itself and available to everyone. since they are the default indi, they are named as OBV and MFI in AB.
but i want to know the construct of OBV & MFI. its a couple of lines code for both. i misplaced it somewhere!
can anybody pls help?

can anyone please post the code of on balance volume (OBV) and money flow index (MFI)?
these are the default indicators of AB!
Plot( OBV(), _DEFAULT_NAME(), ParamColor("Color", colorCycle ), ParamStyle("Style") );

periods = Param( "Periods", 14, 2, 200, 1 );
Plot( MFI(periods), _DEFAULT_NAME(), ParamColor("Color", colorCycle ), ParamStyle("Style") );

Is this you are looking for ?
 

manojborle

Well-Known Member
If the closing price is above the prior close price then:
Current OBV = Previous OBV + Current Volume

If the closing price is below the prior close price then:
Current OBV = Previous OBV - Current Volume

If the closing prices equals the prior close price then:
Current OBV = Previous OBV (no change)

* 1. Typical Price = (High + Low + Close)/3
* 2. Raw Money Flow = Typical Price x Volume
* 3. Money Flow Ratio = (14-period Positive Money Flow)/(14-period Negative Money Flow)
* 4. Money Flow Index = 100 - 100/(1 + Money Flow Ratio)



no manoj! this code is available in AB itself and available to everyone. since they are the default indi, they are named as OBV and MFI in AB.
but i want to know the construct of OBV & MFI. its a couple of lines code for both. i misplaced it somewhere!
can anybody pls help?
 

xsis

Active Member
thks manoj for the logic behind it!
cud u pls put it in afl code!

If the closing price is above the prior close price then:
Current OBV = Previous OBV + Current Volume

If the closing price is below the prior close price then:
Current OBV = Previous OBV - Current Volume

If the closing prices equals the prior close price then:
Current OBV = Previous OBV (no change)

* 1. Typical Price = (High + Low + Close)/3
* 2. Raw Money Flow = Typical Price x Volume
* 3. Money Flow Ratio = (14-period Positive Money Flow)/(14-period Negative Money Flow)
* 4. Money Flow Index = 100 - 100/(1 + Money Flow Ratio)
 
Hi friends
Donchian used one simple trick to avoid bad trades .
Many traders used ma5 &ma20 or ema5 &ema20.
here too simple ma were preferred i dont know why-only backtesting can confirm it.

The others made losses while Donchian made profits.
He used an intelligent and simple filter.
In fact Donchian did not trade on some days after he looked at chart as market opened and second look after certain hours.If no visible opportunity he went off to do other things.Discipline helps but only if you have powerful filters to help you.
filters 1 &2
I am happy the code provided here uses the filters.
first thing
use ema20 as basis-done already
second filter
-points difference contains it but not effectively.

Think about it.
good luck
ford











Code:
TimeFrameSet(in5Minute);
ema5Min=EMA(C,20);
TimeFrameRestore();
EMA_5=TimeFrameExpand(ema5Min, in5Minute, mode=expandFirst);
Plot(EMA_5, "EMA_5_MIN", colorLime, styleThick);  	

TimeFrameSet(in15Minute);
ema15Min=EMA(C,20);
TimeFrameRestore();
EMA_15=TimeFrameExpand(ema15Min, in15Minute, mode=expandFirst);
Plot(EMA_15, "EMA_15_MIN", colorBlueGrey, styleThick);  	

TimeFrameSet(30*in1Minute);
ema30Min=EMA(C,20);
TimeFrameRestore();
EMA_30=TimeFrameExpand(ema30Min, 30*in1Minute, mode=expandFirst);
Plot(EMA_30, "EMA_30_MIN", colorRed, styleThick);  	

TimeFrameSet(inHourly);
ema60Min=EMA(C,20);
TimeFrameRestore();
EMA_60=TimeFrameExpand(ema60Min, inHourly, mode=expandFirst);
Plot(EMA_60, "EMA_60_MIN", colorBlue, styleThick);  	

P = Param("Points Difference", 5,0.5,25,0.5);
Filter = abs(EMA_5- EMA_15) < P AND abs(EMA_5- EMA_30) < P AND abs(EMA_5-EMA_60) < P AND 
         abs(EMA_15-EMA_30) < P AND abs(EMA_15-EMA_60) < P AND abs(EMA_30-EMA_60) < P;

AddColumn(EMA_5, "5minTF-20ema");
AddColumn(EMA_15,"15minTF-20ema");
AddColumn(EMA_30,"30minTF-20ema");
AddColumn(EMA_60,"60minTF-20ema");
Change Param to Adjust the gap, for nifty keep it 5-10 points for BNF can be 10-20 points etc . . .
 

Bewinner

Well-Known Member
Hi friends
Donchian used one simple trick to avoid bad trades .
Many traders used ma5 &ma20 or ema5 &ema20.
here too simple ma were preferred i dont know why-only backtesting can confirm it.

The others made losses while Donchian made profits.
He used an intelligent and simple filter.
In fact Donchian did not trade on some days after he looked at chart as market opened and second look after certain hours.If no visible opportunity he went off to do other things.Discipline helps but only if you have powerful filters to help you.
filters 1 &2
I am happy the code provided here uses the filters.
first thing
use ema20 as basis-done already
second filter
-points difference contains it but not effectively.

Think about it.
good luck
ford
Ford,

what r the filters? are these 5 EMA and 20 EMA coded here by Happy? Please elaborate how they avoid bad trades?
 
Last edited:
Hi

"Cost of Carry" on a Stock Future tricked me today.

I was holding a long position on stock and CoC was showing +ve in TradeTiger, so I was thinking that I will be paid carry cost for a change. At 3:30, number had switched to -ve...

BTW, Any input on How CoC get applied exactly would be nice. Lot size is 9000 so I am getting worried if the damn thing is going to be multiplied to lot size.
I need to understand the calculations that broker is supposed to be doing; Any pointers/inputs would be nice. I do not want CoC formula.
I want to know, how they'll apply it.


Scrip is ASHOKLEY .... It seems bullish as of now... (Disclaimer: However, do not enter just because I've said it here).
 

dell

Well-Known Member
i want to save my database in csv format ..........
get this afl from marketcalls but it is showing syntax error , plz any senior here , rectify the problem in ur free time ................showing error in first line ..............

fh = fopen( “d:AmiBackup”+Name()+”.csv”, “w”);
if( fh )
{
fputs( “Ticker,Date,Open,High,Low,Close,Volume
“, fh );
y = Year();
m = Month();
d = Day();
//r = Hour();
//e = Minute();
//n = Second();
for( i = 0; i < BarCount; i++ )
{
fputs( Name() + “,” , fh );
ds = StrFormat(“%02.0f-%02.0f-%02.0f,”,
y[ i ], m[ i ], d[ i ] );
fputs( ds, fh );

//ts = StrFormat(“%02.0f:%02.0f:%02.0f,”,
//r[ i ],e[ i ],n[ i ] );
//fputs( ts, fh );

qs = StrFormat(“%.4f,%.4f,%.4f,%.4f,%.0f
“,
O[ i ],H[ i ],L[ i ],C[ i ],V[ i ] );
fputs( qs, fh );
}

fclose( fh );
}

Buy = 0;
 

sr114

Well-Known Member
i want to save my database in csv format ..........
get this afl from marketcalls but it is showing syntax error , plz any senior here , rectify the problem in ur free time ................showing error in first line ..............

fh = fopen( “d:AmiBackup”+Name()+”.csv”, “w”);
if( fh )
{
fputs( “Ticker,Date,Open,High,Low,Close,Volume
“, fh );
y = Year();
m = Month();
d = Day();
//r = Hour();
//e = Minute();
//n = Second();
for( i = 0; i < BarCount; i++ )
{
fputs( Name() + “,” , fh );
ds = StrFormat(“%02.0f-%02.0f-%02.0f,”,
y[ i ], m[ i ], d[ i ] );
fputs( ds, fh );

//ts = StrFormat(“%02.0f:%02.0f:%02.0f,”,
//r[ i ],e[ i ],n[ i ] );
//fputs( ts, fh );

qs = StrFormat(“%.4f,%.4f,%.4f,%.4f,%.0f
“,
O[ i ],H[ i ],L[ i ],C[ i ],V[ i ] );
fputs( qs, fh );
}

fclose( fh );
}

Buy = 0;
use this

Code:
/*
Export EOD data to CSV/TXT files 
One file for each stock
In the first line insert the directory you want to save them to, make sure the directory exists
Select your charts to export with the "Apply to" filter in AA window 
Select the timeframe period you want to save as using the AA "Settings"
Press Scan button
by Graham Kavanagh 05 Feb 2004
*/

fh = fopen( "c:\\SAVEDATA\\"+Name()+".csv", "w"); 
if( fh ) 
{ 
   //fputs( "Ticker,Date,Open,High,Low,Close,Volume,Open Int\n", fh ); 
   y = Year(); 
   m = Month(); 
   d = Day(); 
      
   for( i = 0; i < BarCount; i++ ) 
   { 
      fputs( Name() + "," , fh );

      ds = StrFormat("%02.0f/%02.0f/%02.0f,", 
                     d[ i ], m[ i ], y[ i ] ); 
      fputs( ds, fh ); 
     
      qs = StrFormat("%.4f,%.4f,%.4f,%.4f,%.0f,%.0f,\n", 
                     O[ i ],H[ i ],L[ i ],C[ i ],V[ i ],OI [i] ); 
      fputs( qs, fh ); 
   } 

   fclose( fh ); 
} 

Buy = 0;
 

Similar threads