Retrun variable into main

  • État: Closed
  • Prix: $20
  • Propositions reçues: 3
  • Gagnant: laxmikw

Résumé du concours

The following Program works well. However the variable "result" needs to be accessable from outside of "tulind.indicators.sma.indicator([close], [3], function(err, results) {}".
extend the code below that the value of "result is accessable outside of "tulind.indicators.sma.indicator([close], [3], function(err, results) {}"

Update:
To be clear,- the var needs to be go into a global "this.smaExample" to have to possibility to pass this Var later on into other functions.


var tulind = require('tulind');
//Examples assume you have some price data like this:
var close = [4,5,6,6,6,5,5,5,6,4];

//Do a simple moving average on close prices with period of 3.
tulind.indicators.sma.indicator([close], [3], function(err, results) {
console.log("Result of sma is:");
console.log(results[0]);
});





To make this once more more clear:

var tulind = require('tulind');
var _ = require('lodash');

calculate_mytulip = function(params,cb) {
if ( params.indicator === "sma" || params.indicator === "ema"){
tulind.indicators[params.indicator].indicator([params.candleArr.close], [params.period], function(err, results) {
cb({success:true,data:results});
});
}
}

async function async_calculate_mytulip(params){
return new Promise((resolve,reject)=>{
calculate_mytulip(params,function(res){
resolve(res);
})
})
}

method = {}
method.check = async function() {
this.indicators = {
sma20: {},
ema20: {},
}
var envelop = {
indicators: {
ema20: {
name: "ema",
period: 20, // should be an aray later on for another loop inside the each
},
sma20: {
name: "sma",
period: 20, // should be an aray later on for another loop inside the each
},
},
candleArr: {close: [4,5,6,6,6,5,5,5,6,4]},
period: 20,
}

_.each(envelop.indicators, function(params, indicator) {
var answer = async_calculate_mytulip(envelop)
console.log("DEBUG: HERE I NEED THE RESULTS! Result of", indicator, " is:");
console.log(answer)
this.indicators[indicator] = answer;
},this)

console.log("DEBUG: and finnaly it should be here usable:",this.indicators.sma20)
console.log("DEBUG: and here:",this.indicators.ema20)
}


// just for a ogiginal representing of the real environment, please ignore!!!
var main = function(callback) {
callback('get it?');
};

main(method.check);

//-------------------------------------------------------------------------------
// However the results are:
// DEBUG: HERE I NEED THE RESULTS! Result of ema20 is:
// Promise { <pending> }
// DEBUG: HERE I NEED THE RESULTS! Result of sma20 is:
// Promise { <pending> }
// DEBUG: and finnaly it should be here usable: Promise { <pending> }
// DEBUG: and here: Promise { <pending> }

Compétences recommandées

Commentaire de l'employeur

“Great supporter, She was understanding the problematic and developt quick and pricise. Also corrections were done fast and good. I would hire here again !!!!”

Image de profil haxus, Germany.

Meilleures propositions de ce concours

Afficher plus de propositions

Tableau de clarification publique

  • laxmikw
    laxmikw
    • il y a 5 ans

    I have done it.

    • il y a 5 ans
    1. laxmikw
      laxmikw
      • il y a 5 ans

      Please check entry #4

      • il y a 5 ans

Comment commencez des concours

  • Publiez votre concours

    Publiez votre concours Rapide et facile

  • Obtenez des tonnes de propositions

    Obtenez des tonnes de propositions De partout dans le monde

  • Attribuez la meilleure proposition

    Attribuez la meilleure proposition Télécharger les fichiers - Facile !

Publier un concours maintenant ou rejoignez-nous maintenant !