can't get the pinbar right...
can't get the pinbar right...
28 Oct 2018, 18:08
when a bearish pin bar is showing my bot needs to take a sell trade
when a bullish pin bar is showing my bot needs to take a buy trade..
but i cant get it right.. can someone help me?
the difference between high and low should be 100%
when the difference (for a buy trade) between the closing price and the low of the candle is more then 50% of the candle we have a signal
for a sell trade it's about the difference between close and high
what i got right now is this:
protected bool DiffCandleSell(int high, int closed)
{
int Math = 100 / high * closed;
Math = 100 - Math;
if (Math >= 50)
{
return true;
}
return false;
}
protected bool DiffCandleBuy(int low, int closed)
{
int Math = 100 / low * closed;
Math = 100 - Math;
if (Math >= 50)
{
return true;
}
return false;
}
thanks,
Jelle
Replies
jelle2500
29 Oct 2018, 12:46
RE:
freemangreat said:
The result of the indicator will be in the Log. For the best filtering of candles see how to change the function checkCandle.
using System; using cAlgo.API; using cAlgo.API.Internals; using cAlgo.API.Indicators; using cAlgo.Indicators; namespace cAlgo { [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class TestCandle : Indicator { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } [Output("Main")] public IndicatorDataSeries Result { get; set; } bool bFirst =true; protected override void Initialize() { // Initialize and create nested indicators } public override void Calculate(int index) { CANDLE candle; if(IsLastBar && bFirst) { int c =5; // check last 5 bars index -=(c - 1); while(c-- > 0) { candle =checkCandle(index); Print("Bar: {0} - Body: {1} PinUp: {2} PinDown: {3} DiffPins: {4}", index++, candle.fBody, candle.fPinUp, candle.fPinDown, candle.fDiffPins); } bFirst =false; } } //........................................................................ public CANDLE checkCandle(int iCandle) { CANDLE candle = new CANDLE {}; candle.fBody =(MarketSeries.Close[iCandle] - MarketSeries.Open[iCandle]); // if bull candle if(candle.fBody > 0) { candle.fPinUp =(MarketSeries.High[iCandle] - MarketSeries.Close[iCandle]); candle.fPinDown =(MarketSeries.Open[iCandle] - MarketSeries.Low[iCandle]); } // if bear or 0 else { candle.fPinUp =(MarketSeries.High[iCandle] - MarketSeries.Open[iCandle]); candle.fPinDown =(MarketSeries.Close[iCandle] - MarketSeries.Low[iCandle]); } candle.fDiffPins =0; // compare pins if(candle.fPinUp >= Symbol.PipSize && candle.fPinDown >= Symbol.PipSize) if(candle.fPinUp > candle.fPinDown) candle.fDiffPins =(candle.fPinUp / candle.fPinDown); else if(candle.fPinUp < candle.fPinDown) candle.fDiffPins =(-candle.fPinDown / candle.fPinUp); candle.fDiffPins *=100; return(candle); } //------------------------------------------------------------------------ public struct CANDLE { public double fBody; // +/0/- ; bullish - positive, bearish - negative public double fPinUp; // +/0 ; allways positive or 0 public double fPinDown; // +/0 ; allways positive or 0 public double fDiffPins; // +/-(%); PinUp > PinDown (+) : PinUp < PinDown (-) } } }
got it thanks!!
@jelle2500
freemangreat
29 Oct 2018, 00:20
The result of the indicator will be in the Log. For the best filtering of candles see how to change the function checkCandle.
@freemangreat