This website uses cookies to enhance site navigation, analyze site usage, and assist in our marketing efforts. By clicking “Accept All” you are providing your consent to our use of all cookies. Alternatively, please provide your choice by pressing “Customize Cookies”. For more information, please read our Privacy policy
mariolanzetta.cro
22 Jan 2025, 10:38 ( Updated at: 22 Jan 2025, 13:57 )
RE: support for creating a bot to open a position after 3 consecutive candles of the same color occur
firemyst said:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo.Robots
{
[Robot(AccessRights = AccessRights.None)]
public class BarOpenedExample : Robot
{
// Variable to count consecutive bullish candles
private int bullishCount = 0;
// take profit & stop loss
private int takeProfitPips = 15; // 15 pips per take profit
private int stopLossPips = 400; // 400 pips per stop loss
// Perform the operation every time a new candle closes
protected override void OnBar()
{
// Check if the previous candle is bullish (close > open)
if (Bars.ClosePrices.Last(1) > Bars.OpenPrices.Last(1))
{
bullishCount++; // Increment bullish candlestick counter
}
else
{
bullishCount = 0; // Reset the counter if the candle is not bullish
}
// When 3 consecutive bullish candles have been detected
if (bullishCount == 3)
{
// Calculate take profit and stop loss levels based on the defined pips
var stopLossPrice = Symbol.Bid - (stopLossPips * Symbol.PipSize);
var takeProfitPrice = Symbol.Bid + (takeProfitPips * Symbol.PipSize);
ExecuteMarketOrder(TradeType.Buy, SymbolName, 3);
}
bullishCount = 0; // Reset the counter to avoid opening multiple orders
}
}
}
@mariolanzetta.cro