import MetaTrader5 as mt5

MagicNumber = 10001
Lots = 0.1
EnableMartingale = True
MartingaleLotMultiplier = 2
MartingaleAddOnLoss = 0
MartingaleAddOnProfit = 0
MartingaleResetOnLoss = 0
MartingaleResetOnProfit = 0

LastCandleIndex = -1

def OnInit():
    return mt5.INIT_SUCCEEDED

def OnDeinit(reason):
    pass

def OnTick():
    symbol = mt5.symbol_info().name
    Ask = mt5.symbol_info_tick(symbol).ask
    Bid = mt5.symbol_info_tick(symbol).bid

    if mt5.positions_total() > 0:
        return

    CurrentCandleIndex = mt5.copy_rates_from_pos(symbol, mt5.TIMEFRAME_CURRENT, 0, 1)[0][0]

    PreviousHigh = mt5.copy_high_from_pos(symbol, mt5.TIMEFRAME_CURRENT, 1, 1)[0]
    PreviousLow = mt5.copy_low_from_pos(symbol, mt5.TIMEFRAME_CURRENT, 1, 1)[0]
    CandleSize = PreviousHigh - PreviousLow

    TenPipsAboveHigh = PreviousHigh + 10 * mt5.symbol_info(symbol).point
    TenPipsBelowLow = PreviousLow - 10 * mt5.symbol_info(symbol).point

    global LastCandleIndex
    if CurrentCandleIndex != LastCandleIndex:
        if abs(Ask - TenPipsAboveHigh) <= mt5.symbol_info(symbol).point:
            TheStopLoss = PreviousLow - 10 * mt5.symbol_info(symbol).point
            TheTakeProfit = Ask + CandleSize

            MartingaleLots = Lots
            if EnableMartingale:
                MartingaleLots = BetMartingale("MyGroup", symbol, 0, Lots, MartingaleLotMultiplier, 1, MartingaleAddOnLoss, MartingaleAddOnProfit, MartingaleResetOnLoss, MartingaleResetOnProfit)

            mt5.order_send(symbol, mt5.ORDER_TYPE_BUY, MartingaleLots, Ask, 0, TheStopLoss, TheTakeProfit, "", MagicNumber)

            LastCandleIndex = CurrentCandleIndex

        elif abs(Bid - TenPipsBelowLow) <= mt5.symbol_info(symbol).point:
            TheStopLoss = PreviousHigh + 10 * mt5.symbol_info(symbol).point
            TheTakeProfit = Bid - CandleSize

            MartingaleLots = Lots
            if EnableMartingale:
                MartingaleLots = BetMartingale("MyGroup", symbol, 0, Lots, MartingaleLotMultiplier, 1, MartingaleAddOnLoss, MartingaleAddOnProfit, MartingaleResetOnLoss, MartingaleResetOnProfit)

            mt5.order_send(symbol, mt5.ORDER_TYPE_SELL, MartingaleLots, Bid, 0, TheStopLoss, TheTakeProfit, "", MagicNumber)

            LastCandleIndex = CurrentCandleIndex

def BetMartingale(group, symbol, pool, initialLots, multiplyOnLoss, multiplyOnProfit, addOnLoss, addOnProfit, resetOnLoss, resetOnProfit):
info = GetBetTradesInfo(group, symbol, pool, True)


lots = info[0]
profitOrLoss = info[1]
consecutive = info[2]

if lots == 0:
    lots = initialLots
    consecutive = 0
else:
    if profitOrLoss == -1:
        lots = lots * multiplyOnLoss + addOnLoss
        consecutive += 1
        if resetOnLoss > 0 and consecutive >= resetOnLoss:
            lots = initialLots
            consecutive = 0
    elif profitOrLoss == 1:
        lots = initialLots
        consecutive = 0

return lots
def GetBetTradesInfo(group, symbol, pool, last):
lots = 0
profitOrLoss = 0
consecutive = 0


mt5.history_orders_get(0, mt5.ORDER_TIME_CURRENT)
total = mt5.history_deals_total()

for i in range(total - 1, -1, -1):
    ticket = mt5.history_deal_get(i).ticket
    if mt5.history_deal_get(ticket).symbol != symbol or mt5.history_deal_get(ticket).magic != MagicNumber:
        continue

    deal_type = mt5.history_deal_get(ticket).type
    if deal_type == mt5.DEAL_TYPE_BUY or deal_type == mt5.DEAL_TYPE_SELL:
        lots = mt5.history_deal_get(ticket).volume
        profit = mt5.history_deal_get(ticket).profit

        if profit > 0:
            profitOrLoss = 1
            consecutive += 1
        elif profit < 0:
            profitOrLoss = -1
            consecutive += 1
        else:
            profitOrLoss = 0
            consecutive = 0

        if last:
            break

return [lots, profitOrLoss, consecutive]
mt5.initialize()
OnInit()
mt5.run_script(OnTick)
mt5.shutdown()


0.py started	0.py	1	1
    info = GetBetTradesInfo(group, symbol, pool, True)	0.py	64	1
    ^	0.py	64	1
IndentationError: expected an indented block	0.py	64	1
0.py finished in 94 ms		4	1